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
-
#full_const_get(name) ⇒ Object
The constant corresponding to the name.
-
#full_const_set(name, value) ⇒ Object
The constant corresponding to the name.
-
#try_dup ⇒ Object
Override this in a child if it cannot be dup’ed.
Instance Method Details
#full_const_get(name) ⇒ Object
Returns 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.
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_dup ⇒ Object
Override this in a child if it cannot be dup’ed
5 6 7 |
# File 'lib/dm-core/core_ext/try_dup.rb', line 5 def try_dup self.dup end |