Class: SafeMe::DuckType
- Inherits:
-
Object
- Object
- SafeMe::DuckType
- Defined in:
- lib/safe-me/duck_type.rb
Instance Method Summary collapse
-
#initialize(type) ⇒ DuckType
constructor
A new instance of DuckType.
- #to_s ⇒ Object
- #type_of?(obj) ⇒ Boolean
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_s ⇒ Object
14 15 16 |
# File 'lib/safe-me/duck_type.rb', line 14 def to_s "QuacksLike(#{@type})" end |
#type_of?(obj) ⇒ 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 |