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
30 31 32 33 34 |
# File 'lib/extensions/string.rb', line 30 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.
25 26 27 |
# File 'lib/extensions/string.rb', line 25 def ruby_case self.split(/(?=[A-Z])/).join('_').downcase end |