Class: SafeMe::DuckType

Inherits:
Object
  • Object
show all
Defined in:
lib/safe-me/duck_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ DuckType

Returns a new instance of DuckType.



3
4
5
# File 'lib/safe-me/duck_type.rb', line 3

def initialize type
  @type = type
end

Instance Method Details

#to_sObject



14
15
16
# File 'lib/safe-me/duck_type.rb', line 14

def to_s
  "QuacksLike(#{@type})"
end

#type_of?(obj) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/safe-me/duck_type.rb', line 7

def type_of? obj
  @type.public_instance_methods.each do |m|
    return false unless obj.class.public_instance_methods.include? m
  end
  true
end