Class: Object

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

Overview

See Also:

Instance Method Summary collapse

Instance Method Details

#empty?false

provides an empty? check for all objects unless an object already has an empty? check

Returns:

  • (false)


25
26
27
# File 'lib/fqdn_facts/core_ext.rb', line 25

def empty?
  false
end

#present?Boolean

returns true if the object “contains” data (object dependant)

Returns:

  • (Boolean)


32
33
34
# File 'lib/fqdn_facts/core_ext.rb', line 32

def present?
  !empty?
end

#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
# File 'lib/fqdn_facts/core_ext.rb', line 43

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