ITeye博客

ruby 中环绕别名的小例子

bxp2012 · 2013-04-22 07:52 · ruby · 编程语言 · Markdown


class MyClass
   def greet
     puts "Hello!"
   end

   def greet_with_log
     puts "Calling method..."
     greet_without_log
     puts "...method called"
   end

   alias_method :greet_without_log, :greet
   alias_method :greet, :greet_with_log
end

MyClass.new.greet
MyClass.new.greet_without_log

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。