Method: Object#try

Defined in:
lib/fqdn_facts/core_ext.rb

#try(method, *args, &block) ⇒ Object

attempts to call a public method

Parameters:

  • method (Symbol)

    the method to attempt to call

  • args (Array)

    optional arguments to pass to the method

  • block (Block)

    optional block to pass to the method

Returns:

  • the result of the method call, if the method exists, or nil if it doesn’t



43
44
45
46
47
48
49
# File 'lib/fqdn_facts/core_ext.rb', line 43

def try(method, *args, &block)
  begin
    self.public_send(method, *args, &block)
  rescue NoMethodError
    nil
  end
end