From: "David A. Black" Date: 2008-04-30T22:49:50+09:00 Subject: Re: How to create "def method(item)= (value)" ? Hi -- On Wed, 30 Apr 2008, Phillip Gawlowski wrote: > | You could also do: > | > | def param[]=(key,value) > | @params[key] = value > | end > | > | object.param[key] = value > > Oh, I'm gonna steal that idiom if you don't mind. ;) Sorry -- it's wrong. I think I've remembered what I meant to write. This time, let's go all out and try the code! :-) object = Object.new class << object attr_accessor :params end object.params = {} def object.[]=(key,value) @params[key] = value end object[1] = 2 p object.params # { 1 => 2 } Too bad -- I kind of liked my garbled rubbish version :-) David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!