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



-----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-----

.



Relevant Pages

  • Re: How to create "def method(item)= (value)" ?
    ... | def param= ... I'm gonna steal that idiom if you don't mind. ... Iñaki Baz Castillo ...
    (comp.lang.ruby)
  • Re: 2.6 not cat proof
    ... if the cat pisses itself in fright... ... Mind you it's Summer over here in ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Cyclists Dismount Sign
    ... JNugent] ... irrupts from uk.petrolheads (I have one or two specific examples in ... mind, though I like some of the people that get crossposted in), and ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ...
    (uk.rec.cycling)
  • Re: Recursive dup
    ... Iñaki Baz Castillo wrote: ... | I know that I should personalize "dup" method for class A, ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ...
    (comp.lang.ruby)
  • Re: [kde] Kmail & firefox
    ... i did not mind using kmail on occasions that i had to use it. ... Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org ...
    (KDE)