Method: Object#try!

Defined in:
lib/garcon/core_ext/object.rb

#try!(*a, &b) ⇒ Object

Same as #try, but will raise a NoMethodError exception if the receiver is not ‘nil` and does not implement the tried method.

Returns:

Raises:

  • NoMethodError If the receiver is not ‘nil` and does not implement the tried method.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/garcon/core_ext/object.rb', line 74

def try!(*a, &b)
  if a.empty? && block_given?
    if b.arity.zero?
      instance_eval(&b)
    else
      yield self
    end
  else
    public_send(*a, &b)
  end
end