Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rango/core_ext.rb
Instance Method Summary collapse
-
#camel_case ⇒ String
Convert to camel case.
-
#pluralize ⇒ Object
TODO: this certainly isn’t the way to go, but we need to get & refactor extlib at first.
-
#snake_case ⇒ String
Convert to snake case.
Instance Method Details
#camel_case ⇒ String
Convert to camel case.
"foo_bar".camel_case #=> "FooBar"
22 23 24 25 |
# File 'lib/rango/core_ext.rb', line 22 def camel_case return self if self !~ /_/ && self =~ /[A-Z]+.*/ split('_').map{|e| e.capitalize}.join end |
#pluralize ⇒ Object
TODO: this certainly isn’t the way to go, but we need to get & refactor extlib at first
29 30 31 |
# File 'lib/rango/core_ext.rb', line 29 def pluralize "#{self}s" end |
#snake_case ⇒ String
Convert to snake case.
"FooBar".snake_case #=> "foo_bar"
"HeadlineCNNNews".snake_case #=> "headline_cnn_news"
"CNN".snake_case #=> "cnn"
11 12 13 14 15 |
# File 'lib/rango/core_ext.rb', line 11 def snake_case return self.downcase if self =~ /^[A-Z]+$/ self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/ return $+.downcase end |