Class: JsonRpcObjects::Utils::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/json-rpc-objects/utils/object.rb

Overview

Object utility functions.

Since:

  • 0.4.4

Class Method Summary collapse

Class Method Details

.boolean?(object) ⇒ Boolean

Indicates, object is boolean.

Parameters:

  • object (Objectt)

    source object

Returns:

  • (Boolean)

    true if yes, false in otherwise

Since:

  • 0.4.4



78
79
80
# File 'lib/json-rpc-objects/utils/object.rb', line 78

def self.boolean?(object)
    self.instance_of_any? object, [TrueClass, FalseClass]
end

.instance_of_any?(object, *classes) ⇒ Boolean

Returns true if object is an instance of the given classes.

Parameters:

  • object (Object)

    source object

  • classes (Array)

    array of class objects

Returns:

  • (Boolean)

    true if it is, false in otherwise

See Also:

  • #kind_of_any?

Since:

  • 0.4.4



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/json-rpc-objects/utils/object.rb', line 32

def self.instance_of_any?(object, *classes)
    if classes.first.kind_of? ::Array
        classes = classes.first
    end
    
    classes.each do |cls|
        if object.instance_of? cls
            return true
        end
    end
    
    return false
end

.kind_of_any?(object, *classes) ⇒ Boolean

Returns true if one of classes are the class of object, or if one of classes are one of the superclasses of object or modules included in object.

Parameters:

  • object (Object)

    source object

  • classes (Array)

    array of class objects

Returns:

  • (Boolean)

    true if it is, false in otherwise

Since:

  • 0.16.0



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/json-rpc-objects/utils/object.rb', line 57

def self.kind_of_any?(object, *classes)
    if classes.first.kind_of? ::Array
        classes = classes.first
    end
    
    classes.each do |cls|
        if object.kind_of? cls
            return true
        end
    end
    
    return false
end