Class: String

Inherits:
Object show all
Defined in:
lib/watir-webdriver/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseObject

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_caseObject

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