Class: String

Inherits:
Object show all
Defined in:
lib/rucola/rucola_support/core_ext/ruby/string.rb

Instance Method Summary collapse

Instance Method Details

#camel_caseObject

“foo_bar”.camel_case #=> “FooBar”



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rucola/rucola_support/core_ext/ruby/string.rb', line 10

def camel_case    
  if self.include? '_'
    self.split('_').map{|e| e.capitalize}.join
  else
    unless self =~ (/^[A-Z]/)
      self.capitalize
    else
      self
    end
  end
end

#snake_caseObject

“FooBar”.snake_case #=> “foo_bar”



5
6
7
# File 'lib/rucola/rucola_support/core_ext/ruby/string.rb', line 5

def snake_case
  gsub(/\B[A-Z]/, '_\&').downcase
end

#to_constObject

Returns the constant that this string refers to.

"FooBar".to_const # => FooBar
"foo_bar".to_const # => FooBar


26
27
28
# File 'lib/rucola/rucola_support/core_ext/ruby/string.rb', line 26

def to_const
  Object.const_get(camel_case)
end