Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/laborantin/core/monkey_patches.rb
Overview
Some monkey patches on String. Will be moved later to a subclass.
Instance Method Summary collapse
-
#camelize ⇒ Object
Returns a camelized version of a duck_case self ‘some_string’.camelize # => ‘SomeString’.
-
#duck_case ⇒ Object
Returns a duck cased version of camel-like self ‘SomeString’.duck_case # => ‘some_string’.
Instance Method Details
#camelize ⇒ Object
Returns a camelized version of a duck_case self
'some_string'.camelize # => 'SomeString'
28 29 30 |
# File 'lib/laborantin/core/monkey_patches.rb', line 28 def camelize self.split('_').map{|i| i.capitalize}.join('') end |
#duck_case ⇒ Object
Returns a duck cased version of camel-like self
'SomeString'.duck_case # => 'some_string'
34 35 36 |
# File 'lib/laborantin/core/monkey_patches.rb', line 34 def duck_case self.gsub(/([A-Z])/){|s| "_#{$1.downcase}"}.sub(/^_/,'') end |