Forum: Ruby =?euc-kr?B?T3ZlcnJpZGRlbiBBcnJheSNbXT0gbWV0aG9kIHJldHVybnMgd

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9088a1ddc4d22ad891e6bf70b433628e?d=identicon&s=25 unknown (Guest)
on 2006-01-05 20:57
(Received via mailing list)
I overrode Array#[]= like this on irb

class MyArray < Array
alias oldArraySetter []=
def []= (i,o)
self.oldArraySetter(o,i)
return i
end
end
=> nil
irb(main):008:0> ma = MyArray.new
=> []
irb(main):009:0> ma[1] = 0
=> 0
irb(main):010:0> ma["asdf"] = 1
=> 1
irb(main):011:0> ma
=> [1, "asdf"]

I think the expression ma[1] = 0 should return 1 and ma["asdf"] = 1
should return "asdf" but they don't.
Anyone knows why and what should I do?
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-01-05 21:03
(Received via mailing list)
On Jan 5, 2006, at 1:54 PM, ladylazy@teramail.com wrote:

> irb(main):008:0> ma = MyArray.new
> Anyone knows why and what should I do?
Assignment always results in the value that was assigned in Ruby.  We
are not allowed to change this.

Perhaps if you explained what you are trying to accomplish, we could
give an idea or two...

James Edward Gray II
9088a1ddc4d22ad891e6bf70b433628e?d=identicon&s=25 unknown (Guest)
on 2006-01-05 21:27
(Received via mailing list)
>> end
>> I think the expression ma[1] = 0 should return 1 and ma["asdf"] = 1
>
>

I'm just studying now .Thank you.
This topic is locked and can not be replied to.