Class: NilClass

Inherits:
Object show all
Defined in:
lib/reactive_extensions/object/try_rescue.rb

Overview

Ruby’s core NilClass. See documentation for version 2.1.5, 2.0.0, or 1.9.3.

Instance Method Summary collapse

Instance Method Details

#try_rescue(*args, &block) ⇒ Object

The #try_rescue method extends ReactiveSupport’s #try method so it rescues NoMethodErrors and TypeErrors as well as returning nil when called on a nil value.

Like the #try method, #try_rescue takes 1 or more arguments. The first argument is the method to be called on the calling object, passed as a symbol. The others are zero or more arguments that will be passed through to that method, and an optional block to be likewise passed through.

When called on NilClass, #try_rescue always returns nil.

Example:

foo = nil 
foo.try_rescue(:has_key?, :bar)     # => nil


62
63
64
# File 'lib/reactive_extensions/object/try_rescue.rb', line 62

def try_rescue(*args, &block)
  nil 
end