Method: Thor::Util.snake_case

Defined in:
lib/thor/util.rb

.snake_case(str) ⇒ Object

Receives a string and convert it to snake case. SnakeCase returns snake_case.

Parameters

String

Returns

String

[View source]

90
91
92
93
94
# File 'lib/thor/util.rb', line 90

def snake_case(str)
  return str.downcase if str =~ /^[A-Z_]+$/
  str.gsub(/\B[A-Z]/, '_\&').squeeze("_") =~ /_*(.*)/
  Regexp.last_match(-1).downcase
end