Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extensions/string.rb
Overview
Custom extensions to the class String
Instance Method Summary collapse
-
#camel_case ⇒ Object
Change a ruby_cased string to CamelCased.
-
#ruby_case ⇒ Object
Change CamelCased strings to ruby_cased strings It uses the lookahead assertion ?= In this case it basically says match anything followed by a capital letter, but not the capital letter itself.
Instance Method Details
#camel_case ⇒ Object
Change a ruby_cased string to CamelCased
32 33 34 35 36 |
# File 'lib/extensions/string.rb', line 32 def camel_case self.split(/_/).map { |i| i.sub(/^./) { |s| s.upcase } }.join end |
#ruby_case ⇒ Object
Change CamelCased strings to ruby_cased strings It uses the lookahead assertion ?= In this case it basically says match anything followed by a capital letter, but not the capital letter itself.
27 28 29 |
# File 'lib/extensions/string.rb', line 27 def ruby_case self.split(/(?=[A-Z])/).join('_').downcase end |