Class: String
Instance Method Summary collapse
Instance Method Details
#to_camel(method = nil) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/justa/core_ext.rb', line 12 def to_camel method = nil case method when nil return self.split(/_/).map(&:capitalize).join if method == nil when :lower return self.split(/_/)[0] + self.split(/_/)[1..-1].map(&:capitalize).join if method == :lower end end |
#to_snake ⇒ Object
21 22 23 24 25 |
# File 'lib/justa/core_ext.rb', line 21 def to_snake self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase end |