Method: Object#full_const_set

Defined in:
lib/garcon/core_ext/object.rb

#full_const_set(name, value) ⇒ Object

Returns The constant corresponding to the name.

Parameters:

  • name (String)

    The name of the constant to get, e.g. “Garcon::Check”.

  • value (Object)

    The value to assign to the constant.

Returns:

  • (Object)

    The constant corresponding to the name.



227
228
229
230
231
232
233
234
# File 'lib/garcon/core_ext/object.rb', line 227

def full_const_set(name, value)
  list = name.split('::')
  toplevel = list.first.blank?
  list.shift if toplevel
  last = list.pop
  obj = list.empty? ? Object : Object.full_const_get(list.join('::'))
  obj.const_set(last, value) if obj && !obj.const_defined?(last)
end