Ruby 语言 思想驱动生活

July 14, 2006

自己销毁自己的方法。

Filed under: Ruby — liubin @ 16:56
http://redhanded.hobix.com/inspect/methodsThatSelfDestruct.html
  1.  
  2.  class Trial
  3.     def run_me
  4.        def self.run_me; raise Exception, "NO MORE." end
  5.        puts "Your trial period has ended." 
  6.     end
  7.  end
  8.  
  9.  t = Trial.new
  10.  t.run_me
  11.  #=> Your trial period has ended.
  12.  t.run_me
  13.  #=> (trial):3:in `run_me': NO MORE. (Exception)
好像只是只能调用一次而已,对于一个对象。

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress