Class: Cell::Util::Inflector

Inherits:
Object
  • Object
show all
Defined in:
lib/cell/util.rb

Class Method Summary collapse

Class Method Details

.constant_for(name) ⇒ Object

WARNING: this API might change.



17
18
19
20
21
22
23
# File 'lib/cell/util.rb', line 17

def self.constant_for(name)
  class_name = name.split("/").collect do |part|
    part.split('_').collect(&:capitalize).join
  end.join('::')
  
  Object.const_get(class_name, false)
end

.underscore(constant) ⇒ Object

copied from ActiveSupport.



8
9
10
11
12
13
14
# File 'lib/cell/util.rb', line 8

def self.underscore(constant)
  constant.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end