Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski <cmdjackryan@xxxxxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 08:33:30 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Iñaki Baz Castillo wrote:
| 2008/4/30, Phillip Gawlowski <cmdjackryan@xxxxxxxxxxxxxx>:
|> | 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. ;)
|
| I'm sorry, but as I've replied in this thread that method naming
| (using []) is invalid in Ruby :(
Sort of. As a singleton method, you get the syntax error. But not if you
define [] as a method:
irb(main):001:0> def []=(key,value)
irb(main):002:1> end
=> nil
- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com
~ "It's great to have a friend who appreciates an earnest discussion of
ideas." -Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgYdR8ACgkQbtAgaoJTgL8u3wCeJBjJgyJ61Uvxx29wpoiYzx+N
YjUAnjvAmG8+itc/5/337GSz37rH64zm
=f5M/
-----END PGP SIGNATURE-----
.
- 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
- Re: How to create "def method(item)= (value)" ?
- From: Iñaki Baz Castillo
- How to create "def method(item)= (value)" ?
- Prev by Date: Re: How to create "def method(item)= (value)" ?
- Next by Date: Re: What are the weaknesses in Ruby?
- 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
|