Sha256: b0a05105d3491476f92e8c47821aeeeb0055d787acab319322351c3896832398

Contents?: true

Size: 1023 Bytes

Versions: 8

Compression:

Stored size: 1023 Bytes

Contents

class Object

  # @param name<String> The name of the constant to get, e.g. "Merb::Router".
  #
  # @return [Object] The constant corresponding to the name.
  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

  # @param name<String> The name of the constant to get, e.g. "Merb::Router".
  # @param value<Object> The value to assign to the constant.
  #
  # @return [Object] The constant corresponding to the name.
  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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-core-1.1.0.rc2 lib/dm-core/core_ext/object.rb
dm-core-1.1.0.rc1 lib/dm-core/core_ext/object.rb
dm-core-1.0.2 lib/dm-core/core_ext/object.rb
dm-core-1.0.1 lib/dm-core/core_ext/object.rb
dm-core-1.0.0 lib/dm-core/core_ext/object.rb
dm-core-1.0.0.rc3 lib/dm-core/core_ext/object.rb
dm-core-1.0.0.rc2 lib/dm-core/core_ext/object.rb
dm-core-1.0.0.rc1 lib/dm-core/core_ext/object.rb