The second argument

Hello,

what’s the argument of “obj” in: def []=(index,obj) ?

I don’t see it call this method with the second argument.
Thanks

The original code is:

class Array2 < Array

def
if index>0
super(index-1)
else
raise IndexError
end
end

def []=(index,obj)
if index>0
super(index-1,obj)
else
raise IndexError
end
end

end

x = Array2.new

x[1]=5
x[2]=3
x[0]=1 # Error
x[-1]=1 # Error

On Fri, Nov 5, 2010 at 9:10 AM, wroxdb [email protected] wrote:

class Array2 < Array
if index>0

x[1]=5

This is syntactic sugar for

x.[]=(1,5)

which is the method you are asking about.

x[2]=3
x[0]=1 # Error
x[-1]=1 # Error

Jesus.

On Fri, 5 Nov 2010 03:10:26 -0500, wroxdb [email protected] wrote in
[email protected]:

what’s the argument of “obj” in: def []=(index,obj) ?

It’s the value on the right of the equals sign:

a[index] = obj

is the same as

a.[]=(index, obj)

As Jes