Method: RIO::IF::Grande#|

Defined in:
lib/rio/if/grande.rb

#|(destination) ⇒ Object

Grande Pipe Operator

The Rio pipe operator is actually an alternative syntax for calling the IF::Grande#> (copy-to) operator, designed to allow several copy operation to be performed in one line of code, with behavior that mimics the pipe operator commonly available in shells.

If destination is a cmdio, a cmdpipe Rio is returned, and none of the commands are run.

Otherwise the cmdpipe Rio is run with the output of the pipe being copied to the destination. In this case a Rio representing the destination is returned.

If destination is not a Rio it is passed to the Rio constructor as is done with the copy-to operator except that if destination is a String it is assumed to be a command instead of a path.

rio('afile') | rio(?-,'grep i') | rio(?-) # returns rio(?-)
                                          # equivelent to rio(?-, 'grep i') < rio('afile') > rio(?-)

rio('infile') | rio(?-, 'acmd') | rio(?-, 'acmd2') | rio('outfile')
# same as
# acmd = rio(?-,'acmd')
# acmd2 = rio(?-,'acmd2')
# out = rio('outfile')
# acmd < rio('infile')
# acmd2 < acmd
# out < acmd2

rio('afile') | 'acmd' | 'acmd2' | rio('outfile') # same thing

acmdpipe = rio(?-,'acmd') | 'acmd2'
rio('afile') | acmdpipe | rio('outfile') # same thing

acmdpipe1 = rio(?|,'acmd','acmd2')
rio('afile') | acmdpipe1 | rio('outfile') # same thing

acmdpipe2 = rio('afile') | 'acmd' | 'acmd2'
acmdpipe2 | rio('outfile') # same thing

The grande pipe operator can not be used to create a cmdpipe Rio that includes a destination. This must be done using a Rio constructor

cmd_with_output = rio(?|,'acmd',rio('outfile'))
rio('afile') | cmd_with_output # same as above


473
# File 'lib/rio/if/grande.rb', line 473

def |(destination) target | destination end