Class: T::Types::ClassOf
Overview
Validates that an object belongs to the specified class.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#describe_obj(obj) ⇒ Object
overrides Base.
-
#initialize(type) ⇒ ClassOf
constructor
A new instance of ClassOf.
-
#name ⇒ Object
overrides Base.
-
#subtype_of_single?(other) ⇒ Boolean
overrides Base.
-
#valid?(obj) ⇒ Boolean
overrides Base.
Methods inherited from Base
#==, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #recursively_valid?, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(type) ⇒ ClassOf
Returns a new instance of ClassOf.
9 10 11 |
# File 'lib/types/types/class_of.rb', line 9 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/types/types/class_of.rb', line 7 def type @type end |
Instance Method Details
#describe_obj(obj) ⇒ Object
overrides Base
38 39 40 |
# File 'lib/types/types/class_of.rb', line 38 def describe_obj(obj) obj.inspect end |
#name ⇒ Object
overrides Base
14 15 16 |
# File 'lib/types/types/class_of.rb', line 14 def name "T.class_of(#{@type})" end |
#subtype_of_single?(other) ⇒ Boolean
overrides Base
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/types/types/class_of.rb', line 24 def subtype_of_single?(other) case other when ClassOf @type <= other.type when Simple @type.is_a?(other.raw_type) when TypedClass true else false end end |
#valid?(obj) ⇒ Boolean
overrides Base
19 20 21 |
# File 'lib/types/types/class_of.rb', line 19 def valid?(obj) obj.is_a?(Module) && obj <= @type end |