Method: DataMapper::Ext::Object.full_const_set

Defined in:
lib/dm-core/support/ext/object.rb

.full_const_set(obj, name) ⇒ Object .full_const_set(name) ⇒ Object

Sets the specified constant to the given value.

Overloads:

  • .full_const_set(obj, name) ⇒ Object

    Sets the specified constant in obj to the given value.

    Parameters:

    • obj (Object)

      The root object used as origin.

    • name (String)

      The name of the constant to set, e.g. “Merb::Router”.

    • value (Object)

      The value to assign to the constant.

  • .full_const_set(name) ⇒ Object

    Sets the fully-qualified constant to the given value.

    Parameters:

    • name (String)

      The name of the constant to set, e.g. “Merb::Router”.

    • value (Object)

      The value to assign to the constant.

Returns:

  • (Object)

    The constant corresponding to name.



46
47
48
49
50
51
52
53
54
55
# File 'lib/dm-core/support/ext/object.rb', line 46

def self.full_const_set(obj, name, value = nil)
  obj, name, value = ::Object, obj, name if value.nil?

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