Module: Drum::Try

Included in:
Object
Defined in:
lib/drum/utils/ext.rb

Instance Method Summary collapse

Instance Method Details

#try {|value| ... } ⇒ Object?

A lightweight variant of Rails' try that only supports blocks (the other variants are already handled more elegantly using &.).

Yields:

  • (value)

    The block to run if not nil

Yield Parameters:

  • value (Object)

    The non-nil value

Returns:

  • (Object, nil)

    Either the mapped self or nil



10
11
12
13
14
15
16
# File 'lib/drum/utils/ext.rb', line 10

def try
  if self.nil?
    nil
  else
    yield self
  end
end