Class: Object

Inherits:
BasicObject
Defined in:
lib/dm-core/core_ext/object.rb,
lib/dm-core/core_ext/try_dup.rb

Instance Method Summary collapse

Instance Method Details

#full_const_get(name) ⇒ Object

Returns The constant corresponding to the name.

Parameters:

  • name (String)

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

Returns:

  • (Object)

    The constant corresponding to the name.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dm-core/core_ext/object.rb', line 6

def full_const_get(name)
  list = name.split("::")
  list.shift if list.first.blank?
  obj = self
  list.each do |x|
    # This is required because const_get tries to look for constants in the
    # ancestor chain, but we only want constants that are HERE
    obj = obj.const_defined?(x) ? obj.const_get(x) : obj.const_missing(x)
  end
  obj
end

#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. “Merb::Router”.

  • value (Object)

    The value to assign to the constant.

Returns:

  • (Object)

    The constant corresponding to the name.



22
23
24
25
26
27
28
29
# File 'lib/dm-core/core_ext/object.rb', line 22

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

#try_dupObject

Override this in a child if it cannot be dup’ed

Returns:



5
6
7
# File 'lib/dm-core/core_ext/try_dup.rb', line 5

def try_dup
  self.dup
end