Class: Kangaru::Inflectors::Constantiser

Inherits:
Object
  • Object
show all
Defined in:
lib/kangaru/inflectors/constantiser.rb

Class Method Summary collapse

Class Method Details

.constantise(string, root: Object) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/kangaru/inflectors/constantiser.rb', line 6

def self.constantise(string, root: Object)
  as_class    = string.to_class_name
  as_constant = string.to_constant_name

  if root.const_defined?(as_class)
    root.const_get(as_class)
  elsif root.const_defined?(as_constant)
    root.const_get(as_constant)
  end
end