ruby 中环绕别名的小例子_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > ruby 中环绕别名的小例子

ruby 中环绕别名的小例子

 2013/5/19 14:49:14  bxp2012  程序员俱乐部  我要评论(0)
  • 摘要:classMyClassdefgreetputs"Hello!"enddefgreet_with_logputs"Callingmethod..."greet_without_logputs"...methodcalled"endalias_method:greet_without_log,:greetalias_method:greet,:greet_with_logendMyClass.new.greetMyClass.new.greet_without_log
  • 标签:Ruby 例子
class="java">
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
发表评论
用户名: 匿名