Class: Object

Inherits:
BasicObject
Defined in:
lib/types.rb

Overview

Extension of built-in Object class.

Instance Method Summary collapse

Instance Method Details

#type_of?(cls) ⇒ Boolean

Indicates object is type of some class. If class isn’t Type, matches against #kind_of?.

Parameters:

  • cls (Types::Type, Class)

    some type or class specification

Returns:

  • (Boolean)

    true if it is, false in otherwise



92
93
94
95
96
97
98
99
# File 'lib/types.rb', line 92

def type_of?(cls)
    cls_new = cls::new
    if cls_new.kind_of? Types::Type
        cls_new.match_type? self
    else
        self.kind_of? cls
    end
end

#type_of_any?(classes) ⇒ Boolean

Indicates object is type of some class in the list. If class isn’t Type, matches against #kind_of?.

Parameters:

  • classes (Array)

    array of Type or Class objects

Returns:

  • (Boolean)

    true if it is, false in otherwise



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/types.rb', line 109

def type_of_any?(classes)
    if not classes.kind_of? Array
        raise Exception::new("Array expected.")
    end
    
    classes.each do |cls|
        if self.type_of? cls
            return true
        end
    end
    
    return false
end