Method: Symbol#to_trans
- Defined in:
- lib/coroutines/operators.rb
#to_trans ⇒ Object
:call-seq:
sym.to_trans -> transformer
Allows implicit conversion of Symbol to Transformer. The transformer accepts any objects as input, calls the method given by sym on each and outputs all non-nil results of the method. See Proc#to_trans for details.
example:
collector = [] <= :to_s
collector << 1 << 4 << 9
collector.close # => ["1", "4", "9"]
70 71 72 73 74 75 76 77 |
# File 'lib/coroutines/operators.rb', line 70 def to_trans Transformer.new do |y| loop do value = y.await.send self y.yield value unless value.nil? end end end |