class Xumlidot::Types::Constants

Container class

I'm thinking a hash to make lookup quicker …

Public Instance Methods

find_first(constant) click to toggle source

return exact matches

# File lib/xumlidot/types/constants.rb, line 12
def find_first(constant)
  found = find do |klass|
    klass.definition == constant.definition
  end
  return found unless found.nil?

  each do |k|
    k.constants.each do |klass|
       found = klass.constants.find_first(constant)
       return found unless found.nil?
    end
  end
  nil
end
root_namespace_for(constant) click to toggle source

find any constant that is the root of the namespace for the supplied constant

# File lib/xumlidot/types/constants.rb, line 29
def root_namespace_for(constant)
  found = find do |klass|
    klass.definition.root_namespace_for?(constant)
  end

  return found unless found.nil?

  each do |k|
    k.constants.each do |klass|
      return klass if klass.definition.root_namespace_for?(constant)
      found = klass.constants.root_namespace_for(constant)
      return found unless found.nil?
    end
  end
  nil
end
traverse() { |k| ... } click to toggle source
# File lib/xumlidot/types/constants.rb, line 46
def traverse(&block)
  each do |k|
    yield k if block_given?
    k.constants.each do |klass|
      yield klass if block_given?
      klass.constants.traverse(&block)
    end
  end
end