Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rango/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseString

Convert to camel case.

"foo_bar".camel_case          #=> "FooBar"

Returns:

  • (String)

    Receiver converted to camel case.



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

#pluralizeObject

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_caseString

Convert to snake case.

"FooBar".snake_case           #=> "foo_bar"
"HeadlineCNNNews".snake_case  #=> "headline_cnn_news"
"CNN".snake_case              #=> "cnn"

Returns:

  • (String)

    Receiver converted to snake case.



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