Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski <cmdjackryan@xxxxxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 09:02:05 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David A. Black wrote:
|>
|> 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
|
| It's not the singletonness that stops it; you can do this:
|
| def object.[]=(k,v) # etc.
|
| What made my example wrong was that I had concocted an illegal method
| name.
Though, it should (might?) be possible to implemetn something like
Hash's or Array's
hash[key]
array[index]
index methods for plain old object instances, too.
I haven't seen such an implementation, though, and my C and Java fu are
too weak to make sense of JRuby or CRuby.
Maybe Rubinius is a starting point, since it supposedly implement core
classes in Ruby.
- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com
ABORT: Drivel filter is compromised!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgYe9kACgkQbtAgaoJTgL+gSwCghRVTOxl1IlMKSoNZzq98d1F1
+88AnRieQmvx+CEX4pidn6qfqJe/5TT7
=3zqI
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: How to create "def method(item)= (value)" ?
- From: David A. Black
- 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
- Re: How to create "def method(item)= (value)" ?
- From: Phillip Gawlowski
- How to create "def method(item)= (value)" ?
- Prev by Date: Search string for occurneces of words stored in array
- Next by Date: Re: How to create "def method(item)= (value)" ?
- Previous by thread: Re: How to create "def method(item)= (value)" ?
- Next by thread: Re: How to create "def method(item)= (value)" ?
- Index(es):