class Object

def try(*a, &b)

delegator itself.
+SimpleDelegator+ will delegate +try+ to the target instead of calling it on
like direct subclasses of +BasicObject+. For example, using +try+ with
with instances of classes that do not have +Object+ among their ancestors,
Please also note that +try+ is defined on +Object+, therefore it won't work

end
...
@person.try do |p|

block unless it is +nil+:
If +try+ is called without arguments it yields the receiver to a given

otherwise.
to the method the call is attempted and +ArgumentError+ is still raised
The number of arguments in the signature must match. If the object responds

end
...
@posts.try(:each_slice, 2) do |a, b|

Arguments and blocks are forwarded to the method if invoked:

nil.try(:to_i) # => nil, rather than 0

to the method:
+try+ returns +nil+ when called on +nil+ regardless of whether it responds

@person ? @person.name : nil

instead of

@person.try(:name)

This method is defined to be able to write

call returns +nil+ rather than raising an exception.
+public_send+ does, except that if the receiver does not respond to it the
Invokes the public method whose name goes as first argument just like
def try(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    public_send(*a, &b) if respond_to?(a.first)
  end
end