From: Richard Kilmer Date: 2004-06-08T10:40:42+09:00 Subject: Re: How to ducktype a Hash? On 6/7/04 7:37 PM, "Jim Weirich" wrote: >>>> Maybe: >>>> >>>> f['rich'] >>>> f.[firstname] >>>> >>>> It's ugly enough to discourage its use, but it also calls >>> to mind the > > I missed what this syntax (and the other proposals) is supposed to > accomplish and the threading in this topic thread is wonky enough so > that I can't find the parent messages. Could someone fill me in. The key is expressing that a method you are defining is semantically equivalent to a method in another class/module. Contrived example: class NameList def initialize @list = [] end def first_name @list.first end end class Person attr_reader :first_name end class Robot def first_name @first_name end end This says that Robot's first_name method is semantically equivalent to Person's first_name method (with all that that semantics carries with it...which may be a lot, and may not be much). You can "cast" the method call to an instance: r = Robot.new Like this: r.first_name But if you did this: r.first_name It would raise an exception. And perhaps extend respond_to? to include an (optional) Class/Module name. r.respond_to?(:first_name) => true r.respond_to?(:first_name, Person) => true r.respond_to?(:first_name, NameList) => false All this is optional of course. Gavin proposed using <...>, I had originally used {...} -rich