Class: String
Instance Method Summary collapse
-
#camel_case ⇒ Object
Convert from snake case to camel case.
-
#snake_case ⇒ Object
Convert from camel case to snake case.
Instance Method Details
#camel_case ⇒ Object
Convert from snake case to camel case
'foo_bar'.camel_case # => "FooBar"
19 20 21 |
# File 'lib/watir-webdriver/core_ext/string.rb', line 19 def camel_case split('_').map { |e| e.capitalize }.join end |
#snake_case ⇒ Object
Convert from camel case to snake case
'FooBar'.snake_case # => "foo_bar"
9 10 11 |
# File 'lib/watir-webdriver/core_ext/string.rb', line 9 def snake_case gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_') end |