Class: Xumlidot::Types::Constants
- Inherits:
-
Array
- Object
- Array
- Xumlidot::Types::Constants
- Defined in:
- lib/xumlidot/types/constants.rb
Overview
Container class
I’m thinking a hash to make lookup quicker …
Instance Method Summary collapse
-
#find_first(constant) ⇒ Object
return exact matches.
-
#root_namespace_for(constant) ⇒ Object
find any constant that is the root of the namespace for the supplied constant.
- #traverse(&block) ⇒ Object
Instance Method Details
#find_first(constant) ⇒ Object
return exact matches
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
find any constant that is the root of the namespace for the supplied constant
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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(&block) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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 |