Class: Thy::Types::InstanceOf

Inherits:
Object
  • Object
show all
Defined in:
lib/thy/types/instance_of.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ InstanceOf

Returns a new instance of InstanceOf.



6
7
8
# File 'lib/thy/types/instance_of.rb', line 6

def initialize(klass)
  @klass = klass
end

Instance Method Details

#check(value) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/thy/types/instance_of.rb', line 10

def check(value)
  if value.is_a?(@klass)
    Result::Success
  else
    Result::Failure.new("Expected #{value.inspect} to be an instance of: #{@klass.inspect}")
  end
end