Method: Lazier::Object#safe_send

Defined in:
lib/lazier/object.rb

#safe_send(method, *args, &block) ⇒ Object|nil

Sends a method to the object. If the objects doesn't not respond to the method, it returns nil instead of raising an exception.

Parameters:

  • method (Symbol)

    The method to send.

  • args (Array)

    The arguments to send.

  • block (Proc)

    The block to pass to the method.

Returns:

  • (Object|nil)

    The return value of the method or nil, if the object does not respond to the method.



64
65
66
67
68
# File 'lib/lazier/object.rb', line 64

def safe_send(method, *args, &block)
  send(method, *args, &block)
rescue NoMethodError
  nil
end