[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

funky alias problem

polypus

3/28/2006 11:57:00 PM


hi,

if i write

module M
def foo
old_foo
end
end

class X
def foo
puts X
end
def extend_yourself
alias old_foo foo
extend M
end
end

class Y < X
def foo
puts Y
end
end

x = X.new
y = Y.new
x.foo -> X
y.foo -> Y
x.extend_yourself
y.extend_yourself
x.foo -> X
y.foo -> X !!!

the behaviour i want though is

y.foo -> Y

what is the best way?

thanks many

--
Posted via http://www.ruby-....


3 Answers

polypus

3/29/2006 12:43:00 AM

0


well solving my own problem, i think the simplest way of doing this is
probably

module M
def foo
puts M
@old_foo.call
end
end


class X
def foo
puts X
end
def ext
@old_foo = method :foo
end
end

class Y < X
def foo
puts Y
end
end

anyway, still keen to hear any second opinions.


--
Posted via http://www.ruby-....


Ara.T.Howard

3/29/2006 2:35:00 AM

0

polypus

3/29/2006 4:08:00 AM

0

thanks that's pretty

--
Posted via http://www.ruby-....