Tips – Rewrite private method gracefully

Posted by AllenWei | Posted in RubyOnRails, Tips | Posted on 15-02-2010-05-2008

View Comments




<br
class Test
  private
  def words
    puts "origin word"
  end
end

Test.class_eval do
  alias_method :origin_words, :words
 
  def words
    puts "haha"
    origin_words
    puts "haha end"
  end
end

Test.new.send(:words)


Ads Plugin created by Jake Ruston's Wordpress Plugins - Powered by and football database.