Module: DataMapper::Ext::Object
- Defined in:
- lib/dm-core/support/ext/object.rb
Class Method Summary collapse
-
.full_const_get(obj, name = nil) ⇒ Object
Returns the value of the specified constant.
-
.full_const_set(obj, name, value = nil) ⇒ Object
Sets the specified constant to the given
value
.
Class Method Details
.full_const_get(obj, name) ⇒ Object .full_const_get(name) ⇒ Object
Returns the value of the specified constant.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dm-core/support/ext/object.rb', line 17 def self.full_const_get(obj, name = nil) obj, name = ::Object, obj if name.nil? list = name.split("::") list.shift if DataMapper::Ext.blank?(list.first) 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(obj, name) ⇒ Object .full_const_set(name) ⇒ Object
Sets the specified constant to the given value
.
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 |