Class: String
Instance Method Summary collapse
-
#snake_case ⇒ String
Convert to snake case.
-
#to_const_path ⇒ String
Convert a constant name to a path, assuming a conventional structure.
Instance Method Details
#snake_case ⇒ String
Convert to snake case.
"FooBar".snake_case #=> "foo_bar"
"HeadlineCNNNews".snake_case #=> "headline_cnn_news"
"CNN".snake_case #=> "cnn"
12 13 14 15 16 |
# File 'lib/nanite/util.rb', line 12 def snake_case return self.downcase if self =~ /^[A-Z]+$/ self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/ return $+.downcase end |
#to_const_path ⇒ String
Convert a constant name to a path, assuming a conventional structure.
"FooBar::Baz".to_const_path # => "foo_bar/baz"
27 28 29 |
# File 'lib/nanite/util.rb', line 27 def to_const_path snake_case.gsub(/::/, "/") end |