Class: Symbol
Instance Method Summary collapse
-
#<=(source) ⇒ Object
:call-seq: sym <= trans -> new_trans sym <= enum -> new_enum.
-
#>=(sink) ⇒ Object
:call-seq: sym >= trans -> new_trans sym >= sink -> new_consumer.
-
#to_trans ⇒ Object
:call-seq: sym.to_trans -> transformer.
Instance Method Details
#<=(source) ⇒ Object
:call-seq:
sym <= trans -> new_trans
sym <= enum -> new_enum
Equivalent to sym.to_trans <= trans/enum, except that it uses a more efficient implementation.
212 213 214 |
# File 'lib/coroutines.rb', line 212 def <=(source) to_proc <= source end |
#>=(sink) ⇒ Object
:call-seq:
sym >= trans -> new_trans
sym >= sink -> new_consumer
Equivalent to sym.to_trans >= trans/sink, except that it uses a more efficient implementation.
222 223 224 |
# File 'lib/coroutines.rb', line 222 def >=(sink) to_proc >= sink end |
#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"]
197 198 199 200 201 202 203 204 |
# File 'lib/coroutines.rb', line 197 def to_trans Transformer.new do |y| loop do value = y.await.send self y.yield value unless value.nil? end end end |