From: Adam Gardner Date: 2009-05-16T04:18:05+09:00 Subject: Re: obj.attr(qualifier) = value -- possible? Rick Denatale wrote: > On Fri, May 15, 2009 at 3:00 PM, Michael Schuerig > wrote: >> �end >> � � �... >> � �end >> �end >> end >> >> Neither is valid Ruby, apparently. Is there another, working way? > > I don't think you can get the calling syntax you want. The best you > can do I think is > > obj.attr = qualifier, value > Well, you could always go with obj.attr[qualifier] = value irb(main):004:0> class Ooo irb(main):005:1> attr_reader :attr irb(main):006:1> def initialize irb(main):007:2> @attr = {} irb(main):008:2> end irb(main):009:1> end => nil irb(main):010:0> obj = Ooo.new => # irb(main):011:0> obj.attr[:happy] = :sad => :sad irb(main):012:0> obj.attr => {:happy=>:sad} irb(main):013:0> obj.attr[:happy] => :sad irb(main):014:0> This example used a hash because it's easy, buy could make @attr be any class that accepts the []= method, including a class of your own. -- Posted via http://www.ruby-forum.com/.