Module: Stronger::TypeChecking::Implementers

Defined in:
lib/stronger/type_checking.rb

Instance Method Summary collapse

Instance Method Details

#<(type) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/stronger/type_checking.rb', line 22

def <(type)
  if type.is_a?(Interface)
    instance_implements?(type)
  else
    super(type)
  end
end

#>(type) ⇒ Object



30
31
32
# File 'lib/stronger/type_checking.rb', line 30

def >(type)
  !(self <= type)
end

#implement(interface) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/stronger/type_checking.rb', line 38

def implement(interface)
  interface.methods.each do |name|
    define_method(name) do
      raise NotImplementedError, "#{self.class} should implement #{name}!"
    end
  end
end

#instance_implements?(interface) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/stronger/type_checking.rb', line 34

def instance_implements?(interface)
  (interface.methods - instance_methods).empty?
end