Class: Enumerable::TreeDelegator
- Includes:
- Enumerable
- Defined in:
- lib/agents/sets/enum/tree.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#child_map ⇒ Object
readonly
Returns the value of attribute child_map.
-
#child_name ⇒ Object
readonly
Returns the value of attribute child_name.
-
#output_type ⇒ Object
readonly
Returns the value of attribute output_type.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #get_children(cur) ⇒ Object
-
#initialize(root, child_spec = nil, *args, &child_proc) ⇒ TreeDelegator
constructor
A new instance of TreeDelegator.
Methods included from Enumerable
#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe
Constructor Details
#initialize(root, child_spec = nil, *args, &child_proc) ⇒ TreeDelegator
Returns a new instance of TreeDelegator.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/agents/sets/enum/tree.rb', line 11 def initialize root, child_spec = nil, *args, &child_proc @root = root @args = args @output_type = :nodes case child_spec when Symbol @child_name = child_spec when String @child_name = child_spec.intern when nil @child_map = child_proc else unless child_spec.respond_to? :[] raise ArgumentError, "child_spec must be a method name or respond to []." end @child_map = child_spec end unless @child_name or @child_map raise ArgumentError, "no child-getter specified." end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/agents/sets/enum/tree.rb', line 8 def args @args end |
#child_map ⇒ Object (readonly)
Returns the value of attribute child_map.
8 9 10 |
# File 'lib/agents/sets/enum/tree.rb', line 8 def child_map @child_map end |
#child_name ⇒ Object (readonly)
Returns the value of attribute child_name.
8 9 10 |
# File 'lib/agents/sets/enum/tree.rb', line 8 def child_name @child_name end |
#output_type ⇒ Object (readonly)
Returns the value of attribute output_type.
8 9 10 |
# File 'lib/agents/sets/enum/tree.rb', line 8 def output_type @output_type end |
Instance Method Details
#get_children(cur) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/agents/sets/enum/tree.rb', line 37 def get_children cur (if @child_name cur.send @child_name, *@args else @child_map[cur, *@args] end).to_a end |