class String
Start monkey patch of Object::String
Public Instance Methods
classify()
click to toggle source
Classify a string @example
'test_class'.classify #=> TestClass
@example
'testclass'.classify #=> Testclass
# File lib/chemlab/core_ext/string/inflections.rb, line 10 def classify split('_').map(&:capitalize).join end
underscore()
click to toggle source
Underscore a multi-worded string @example
'TestClass'.underscore #=> 'test_class'
@example
'Class'.underscore #=> 'class'
# File lib/chemlab/core_ext/string/inflections.rb, line 19 def underscore chars.each_with_object(+'') do |c, str| str << '_' if c.match?(/[A-Z]/) && !str.size.zero? str << c.downcase end end