Overridden Array#[]= method returns unexpected value

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?

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

···

On Jan 5, 2006, at 1:54 PM, ladylazy@teramail.com wrote:

I overrode Array#= like this on irb

class MyArray < Array
alias oldArraySetter =
def = (i,o)
self.oldArraySetter(o,i)
return i
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?

I'm just studying now .Thank you.

···

On Jan 5, 2006, at 1:54 PM, ladylazy@teramail.com wrote:

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?

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