Class: String

Inherits:
Object
  • Object
show all
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

Instance Method Details

#camelizeObject

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_caseObject

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