Module: Darthjee::CoreExt::Object

Included in:
Object
Defined in:
lib/darthjee/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#is_any?(*classes) ⇒ ::TrueClass, ::FalseClass

Checks if object is any of the given classes

Examples:

object = [1, 2, 3]

object.is_any?(Hash,  Class)      # false
object.is_any?(Hash,  Array)      # true
object.is_any?(Enumerable, Class) # true

Parameters:

Returns:

  • (::TrueClass, ::FalseClass)


20
21
22
23
24
# File 'lib/darthjee/core_ext/object.rb', line 20

def is_any?(*classes)
  classes.any? do |clazz|
    is_a?(clazz)
  end
end

#trueful?::TrueClass, ::FalseClass

Checks if object is evaluated to true

Examples:

nil.trueful? # returns false
[].trueful?  # returns true
{}.trueful?  # returns true
"".trueful?  # returns true

Returns:

  • (::TrueClass, ::FalseClass)


35
36
37
38
39
# File 'lib/darthjee/core_ext/object.rb', line 35

def trueful?
  # rubocop: disable Style/DoubleNegation
  !!self
  # rubocop: enable Style/DoubleNegation
end