Hi sir Enab (aka WATANABE Hirofumi [mailto:eban@os.rim.or.jp]):
You answered precisely last Monday, December 09, 2002 6:43 PM:
module MyArray
def =(x, y)
super x, y
self
end
enda = [1,2,3,4]
a.extend MyArray
p((a[1]=6).sort) #=> [1, 3, 4, 6]
You’re solution is great, very flexible and safe too (as mentioned by David
and Gavin).
I have one request though, if it is not too much. Is it possible to define a
“new” method, say <= ? like,
module MyArray
def <= (x, y) #changed here
super x, y
self
end
end
so that,
a = [1,2,3,4]
a.extend MyArray
p((a[1] <= 6).sort) #=> [1, 3, 4, 6]
This way I do not pose danger to = use…
I tried but I get a syntax error. Does this mean, I cannot define new ones?
Sorry, If I do not know what I’m talking/asking about. Your sample codes
looks very simple (and tempting) and works right out of the box. That is why
I thought it would be simple to modify. Maybe, I missed basic underlying
principle. Pls enlighten.
–
eban
Many thanks.
kind regards,
-botp