Class: Object

Inherits:
BasicObject
Defined in:
lib/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#try_chain(*args) ⇒ Object

Chain calls Object#try

Examples:

%w(ABC DEF GHI).try_chain(:first) # => "ABC"
%w(ABC DEF GHI).try_chain(:first, :chop, :succ) # => "AC"
%w(ABC DEF GHI).try_chain(:first, :invalid_method, :chop, :succ) # => nil

Returns:

  • (Object)

    result of Object#try


11
12
13
# File 'lib/core_ext/object.rb', line 11

def try_chain(*args)
  args.inject(self) { |_, method| _.try(method) }
end