Module: Fried::Typings::Type
- Included in:
- ArrayOf, EnumeratorOf, HashOf, Is, IsStrictly, OneOf, StrictlyOneOf, TupleOf
- Defined in:
- lib/fried/typings/type.rb
Overview
Protocol to validate object type
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares own class with other object (which should be a class).
-
#call(obj) ⇒ Object
The passed object.
-
#valid?(obj) ⇒ Boolean
True if object is of valid type.
Class Method Details
.included(klass) ⇒ Object
7 8 9 10 11 |
# File 'lib/fried/typings/type.rb', line 7 def self.included(klass) klass.instance_eval do include Comparable end end |
Instance Method Details
#<=>(other) ⇒ Object
Compares own class with other object (which should be a class)
15 16 17 |
# File 'lib/fried/typings/type.rb', line 15 def <=>(other) self.class <=> other end |
#call(obj) ⇒ Object
Returns the passed object.
22 23 24 25 |
# File 'lib/fried/typings/type.rb', line 22 def call(obj) invalid_type!(obj) unless valid?(obj) obj end |
#valid?(obj) ⇒ Boolean
Returns true if object is of valid type.
29 30 31 |
# File 'lib/fried/typings/type.rb', line 29 def valid?(obj) raise NotImplementedError end |