Dynamic alias

T

Trans

Honestly, alias bugs me to know end. When meta-programming, alias is
notorious for causing problems. Not only is it a keyword (yuk), but it
is inherently static.

Well, it doesn't fix everything of course, but here's a little snip
that came to me today to take some of the static edge off:

class Module
alias _alias_method alias_method

def alias_method(name,target)
begin
_alias_method(name,target)
rescue
module_eval %{
def #{name}(*a,&b)
#{target}(*a,*b)
end
}
end
end
end

Now it's possible to alias a method that's hasn't been defined yet.

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top