Class: StrongType::MethodTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/strong_ruby/strong_type/method_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attrs) ⇒ MethodTypes

Returns a new instance of MethodTypes.



5
6
7
# File 'lib/strong_ruby/strong_type/method_types.rb', line 5

def initialize(*attrs)
  @types = attrs
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



3
4
5
# File 'lib/strong_ruby/strong_type/method_types.rb', line 3

def types
  @types
end

Instance Method Details

#validate!(*attrs) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/strong_ruby/strong_type/method_types.rb', line 9

def validate!(*attrs)
  type_check = types.each_with_index.map do |type, i|
    type === attrs[i]
  end.all?
  unless type_check
    raise StandardError.new("types are incorrect")
  end
end