module Fried::Typings::Type
Protocol to validate object type
Public Class Methods
included(klass)
click to toggle source
# File lib/fried/typings/type.rb, line 7 def self.included(klass) klass.instance_eval do include Comparable end end
Public Instance Methods
<=>(other)
click to toggle source
Compares own class with other object (which should be a class) @param other [Class,Module]
# File lib/fried/typings/type.rb, line 15 def <=>(other) self.class <=> other end
call(obj)
click to toggle source
@param obj any object @return the passed object @raise [TypeError] should be raised if {#valid?} is false
# File lib/fried/typings/type.rb, line 22 def call(obj) invalid_type!(obj) unless valid?(obj) obj end
valid?(obj)
click to toggle source
@param obj any object @return [Boolean] true if object is of valid type
# File lib/fried/typings/type.rb, line 29 def valid?(obj) raise NotImplementedError end
Protected Instance Methods
invalid_type!(obj)
click to toggle source
# File lib/fried/typings/type.rb, line 35 def invalid_type!(obj) raise TypeError, "Type of `obj` is #{obj.class} - #{obj.inspect}" end