alias_method 'stickiness'

A

Ara.T.Howard

any idea if this behaviour is intended or not?


mussel:~/eg/ruby/nrtlib/nrtlib-0.0.0 > cat a.rb
#
# the problem
#
module NRT
class Subscription
def process_incoming
raise NotImplementedError
end
alias_method "run", "process_incoming"
end
class OLSSubscription < Subscription
def process_incoming
p 42
end
end
end
begin; NRT::OLSSubscription::new.run ;rescue Exception => e; p e; end

#
# an easy solution
#
module NRT
class Subscription
def self::anonym dst, src
module_eval %Q[ def #{ dst }(*a, &b) #{ src }(*a, &b) end ]
end
anonym "run", "process_incoming"
end
end
NRT::OLSSubscription::new.run



mussel:~/eg/ruby/nrtlib/nrtlib-0.0.0 > ruby a.rb
#<NotImplementedError: NotImplementedError>
42


this seems odd to me.

-a
 
A

ara.t.howard

I've just gotten used to using alias *only* for metaprogramming, and not
for ordinary API definition.

Maybe it would be nice if the alias keyword were reserved for the
delegation style definition, like your anonym method, and the
metaprogramming interface were something like this:

class Foo
# alias :m_copy :m # old way
instance_method_at[:m_copy] = instance_method:)m) # new way
# now you can wrap :m_copy however you want
end

This makes it more clear that you are making a copy, so it might be less
confusing.

i like that. what do you think about

class Foo
delegate :src, :dst
end

??

-a
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top