Class: Enumerable::Pipe
- Includes:
- Enumerable
- Defined in:
- lib/agents/sets/enum/pipe.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#filter_map ⇒ Object
readonly
Returns the value of attribute filter_map.
-
#filter_name ⇒ Object
readonly
Returns the value of attribute filter_name.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(enum, filter_spec = nil, *args, &filter_proc) ⇒ Pipe
constructor
A new instance of Pipe.
Methods included from Enumerable
#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe
Constructor Details
#initialize(enum, filter_spec = nil, *args, &filter_proc) ⇒ Pipe
Returns a new instance of Pipe.
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/pipe.rb', line 10 def initialize enum, filter_spec = nil, *args, &filter_proc @enum = enum @args = args case filter_spec when Symbol @filter_name = filter_spec when String @filter_name = filter_spec.intern when nil @filter_map = filter_proc else unless filter_spec.respond_to? :[] raise ArgumentError, "filter_spec must be a method name or respond to []." end @filter_map = filter_spec end unless @filter_name or @filter_map raise ArgumentError, "no filter specified." end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/agents/sets/enum/pipe.rb', line 8 def args @args end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
8 9 10 |
# File 'lib/agents/sets/enum/pipe.rb', line 8 def enum @enum end |
#filter_map ⇒ Object (readonly)
Returns the value of attribute filter_map.
8 9 10 |
# File 'lib/agents/sets/enum/pipe.rb', line 8 def filter_map @filter_map end |
#filter_name ⇒ Object (readonly)
Returns the value of attribute filter_name.
8 9 10 |
# File 'lib/agents/sets/enum/pipe.rb', line 8 def filter_name @filter_name end |
Instance Method Details
#each ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/agents/sets/enum/pipe.rb', line 35 def each if @filter_name filter_name = @filter_name = filter_name, *@args @enum.each { |entry| yield entry.send * } elsif @filter_map filter_map = @filter_map args = *@args @enum.each { |entry| yield filter_map[entry, *args] } end end |