I checked out some of the new Ruby features at theluckystiff.net and saw
’ducktype’ing. It sounds uber cool. Is this what is meant by ducktype?
(The code may be inelegant; I don’t know; I’m still a Ruby Nuby). Please
correct me if I got it wrong.
···
######################################################################
ducktype
This method accepts two parameters. The first is an array of
#strings. The second is anything. As long as every string in x is the
#name of one of the methods provided by y, the method will return
#true. I grunged the return value to make sure it only returns true
#or false.
def ducktype (x, y)
!(!( x.map{|f| break false if !y.respond_to?(f) }))
end
#####################################################################
This is sort of like having a discovered mixin. Neat.
BTW, thanks Matz and all the contribs. This is fun!
Drew