tsawyer
1/19/2005 11:33:00 PM
Very interesting article thank you!
Slithers are not the only ones who can monkey around ;-)
<pre>
class Duck
def walk
puts "walk, walk"
end
def to_duck
self
end
end
class Mallard
def waddle
puts "waddle, waddle"
end
def to_duck
class << self
def walk
waddle
end
end
self
end
end
def duckmoto(d,k=d.to_duck)
k.walk
end
d = Duck.new
m = Mallard.new
duckmoto(d)
duckmoto(m)
</pre>
This seems very close to what is being described as "monkey typing".
Obviously there are few missing features and a couple caveats to the
interface here, but they should be easy enough to tackle if this was
thought a good idea.
But I don't know if I'm prepared for "monkey" terminology. Bars,
Barrells, and Wrenches suddenly come to mind. And after all, we just
got a real duck of our own (Mr. Type) a few weeks ago! Hmm... I suppose
they can be friends. Friends are nice. But I worry how his shoulder
horse might feel about these new arrangements ;-)
T.