Class: Fried::Typings::OneOf

Inherits:
Object
  • Object
show all
Includes:
MetaType, Type
Defined in:
lib/fried/typings/one_of.rb

Overview

Checks if the object #is_a? object of the passed types

Instance Method Summary collapse

Methods included from Type

#<=>, #call, included

Methods included from MetaType

included

Constructor Details

#initialize(*types) ⇒ OneOf

Returns a new instance of OneOf.



18
19
20
# File 'lib/fried/typings/one_of.rb', line 18

def initialize(*types)
  @types = types
end

Instance Method Details

#valid?(obj) ⇒ Boolean

Returns:



22
23
24
25
26
# File 'lib/fried/typings/one_of.rb', line 22

def valid?(obj)
  types.any? do |type|
    Is[type].valid?(obj)
  end
end