Re: How to create "def method(item)= (value)" ?
- From: "David A. Black" <dblack@xxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 08:49:50 -0500
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!
.
- Follow-Ups:
- Re: How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- Re: How to create "def method(item)= (value)" ?
- References:
- How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski
- Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski
- How to create "def method(item)= (value)" ?
- Prev by Date: Re: I have installed Ruby-186-26, why is there no usr/local/bin/ruby directory?
- Next by Date: Search string for occurneces of words stored in array
- Previous by thread: Re: How to create "def method(item)= (value)" ?
- Next by thread: Re: How to create "def method(item)= (value)" ?
- Index(es):
Relevant Pages
|