Class: Enumerable::LinkedListDelegator
- Includes:
- Enumerable
- Defined in:
- lib/agents/sets/enum/by.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#next_map ⇒ Object
readonly
Returns the value of attribute next_map.
-
#next_name ⇒ Object
readonly
Returns the value of attribute next_name.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(first, next_spec = nil, *args, &next_proc) ⇒ LinkedListDelegator
constructor
A new instance of LinkedListDelegator.
Methods included from Enumerable
#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe
Constructor Details
#initialize(first, next_spec = nil, *args, &next_proc) ⇒ LinkedListDelegator
Returns a new instance of LinkedListDelegator.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/agents/sets/enum/by.rb', line 10 def initialize first, next_spec = nil, *args, &next_proc @first = first @args = args case next_spec when Symbol @next_name = next_spec when String @next_name = next_spec.intern when nil @next_map = next_proc else unless next_spec.respond_to? :[] raise ArgumentError, "next_spec must be a method name or respond to []." end @next_map = next_spec end unless @next_name or @next_map raise ArgumentError, "no next-getter specified." end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/agents/sets/enum/by.rb', line 8 def args @args end |
#first ⇒ Object (readonly)
Returns the value of attribute first.
8 9 10 |
# File 'lib/agents/sets/enum/by.rb', line 8 def first @first end |
#next_map ⇒ Object (readonly)
Returns the value of attribute next_map.
8 9 10 |
# File 'lib/agents/sets/enum/by.rb', line 8 def next_map @next_map end |
#next_name ⇒ Object (readonly)
Returns the value of attribute next_name.
8 9 10 |
# File 'lib/agents/sets/enum/by.rb', line 8 def next_name @next_name end |
Instance Method Details
#each ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/agents/sets/enum/by.rb', line 35 def each cur = @first if @next_name next_name = @next_name = next_name, *@args while cur yield cur cur = cur.send * end elsif @next_map next_map = @next_map args = @args while cur yield cur cur = next_map[cur, *args] end end self end |