Class: String
- Defined in:
- lib/rucola/rucola_support/core_ext/ruby/string.rb
Instance Method Summary collapse
-
#camel_case ⇒ Object
“foo_bar”.camel_case #=> “FooBar”.
-
#snake_case ⇒ Object
“FooBar”.snake_case #=> “foo_bar”.
-
#to_const ⇒ Object
Returns the constant that this string refers to.
Instance Method Details
#camel_case ⇒ Object
“foo_bar”.camel_case #=> “FooBar”
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rucola/rucola_support/core_ext/ruby/string.rb', line 10 def camel_case if self.include? '_' self.split('_').map{|e| e.capitalize}.join else unless self =~ (/^[A-Z]/) self.capitalize else self end end end |
#snake_case ⇒ Object
“FooBar”.snake_case #=> “foo_bar”
5 6 7 |
# File 'lib/rucola/rucola_support/core_ext/ruby/string.rb', line 5 def snake_case gsub(/\B[A-Z]/, '_\&').downcase end |