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
-
#initialize(type) ⇒ ClassOf
constructor
A new instance of ClassOf.
- #name ⇒ Object
- #subtype_of_single?(other) ⇒ Boolean
- #valid?(obj) ⇒ Boolean
Methods inherited from Base
#==, #error_message_for_obj, #hash, method_added, #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
34 35 36 |
# File 'lib/types/types/class_of.rb', line 34 def describe_obj(obj) obj.inspect end |
#name ⇒ Object
14 15 16 |
# File 'lib/types/types/class_of.rb', line 14 def name "T.class_of(#{@type})" end |
#subtype_of_single?(other) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/types/types/class_of.rb', line 24 def subtype_of_single?(other) case other when ClassOf @type <= other.type else false end end |
#valid?(obj) ⇒ Boolean
19 20 21 |
# File 'lib/types/types/class_of.rb', line 19 def valid?(obj) obj.is_a?(Module) && obj <= @type end |