Class: NilClass

Inherits:
Object
  • Object
show all
Defined in:
lib/ripe/blocks/block.rb

Overview

NilClass is monkey-patched+ to provide syntactic sugar for Block#| and Block#+ by treating nil like an empty block.

Instance Method Summary collapse

Instance Method Details

#+(block) ⇒ Block

If attempting to compose a new block with a nil element, ignore the nil element.

Parameters:

  • block (Block)

    a block

Returns:

  • (Block)

    the block parameter



140
141
142
# File 'lib/ripe/blocks/block.rb', line 140

def +(block)
  self.|(block)
end

#|(block) ⇒ Block

If attempting to compose a new block with a nil element, ignore the nil element.

Parameters:

  • block (Block)

    a block

Returns:

  • (Block)

    the block parameter

Raises:

  • (NoMethodError)


132
133
134
135
# File 'lib/ripe/blocks/block.rb', line 132

def |(block)
  raise NoMethodError unless Ripe::Blocks::Block > block.class
  block
end