module Drum::Try

Public Instance Methods

try() { |self| ... } click to toggle source

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

@yield [value] The block to run if not nil @yieldparam [Object] value The non-nil value @return [Object, nil] Either the mapped self or nil

# File lib/drum/utils/ext.rb, line 10
def try
  if self.nil?
    nil
  else
    yield self
  end
end