Re: How to create "def method(item)= (value)" ?



2008/4/30, David A. Black <dblack@xxxxxxxxxxx>:

You could also do:

def param[]=(key,value)
@params[key] = value
end

object.param[key] = value

That's not valid, a method cannot contain []:

irb> def hola[]() end
SyntaxError: compile error
syntax error, unexpected '[', expecting '\n' or ';'
def hola[]() end


Of course, then one might as well do:

attr_reader :params

on the object, and them:

object.params[key] = value

Yes, but that is not valid for me since I need to exec some extra code
so I need to create an abstraction layer to access @params.


Thanks.


--
Iñaki Baz Castillo
<ibc@xxxxxxxxx>


Relevant Pages