From: Eric Mahurin Date: 2005-06-09T22:46:29+09:00 Subject: Re: making a duck --- nobuyoshi nakada wrote: > Hi, > > At Thu, 9 Jun 2005 01:30:53 +0900, > Eric Mahurin wrote in [ruby-talk:144892]: > > # make == look like === > > digit = (?0..?9).duck(:==,:===) > > # match to a string of 4 digits > > # Proc responds to [] like a String/Array > > cursor.scan(proc{|i|(i<4)? digit : nil}) > > It would be called as `alias', I guess. > > -- > Nobu Nakada I don't care too much what the method names are. Below is the implementation I was thinking. This gives you 3 ways to make a "duck" (a minimal object for a duck-typed argument of a method): digit = (?0..?9).duck(:==,:include?,:to_s,:inspect) alpha = Object.duck(size: proc{26}, :== => (?a..?z).method(:===) ) test = Object.duck(:hi) {puts "hello world!"} Any chance of getting something like this in the standard lib? Your "Behavior" implementation is fine too. class Object def duck(*new_old) obj = Object.new klass = (class<