From: pharrington Date: 2009-12-19T05:30:20+09:00 Subject: Re: How to reopen the puts method On Dec 18, 1:56 pm, Adam Lauper wrote: > I am looking for some additional detail regarding the puts method.  Hows > does the basic puts method work? > > module Kernel >   def self.puts text >     $stdout.puts "New_Text" >   end > end > > # the following code doesn't actually call the Kernel puts method I've > redefined. > puts "Hello, World!" > > # however, this code does. > Kernel.puts "Hello, World!" > > I would like to insert a debug flag into the basic puts method and > suppress the output unless a flag is true.  Something like this... > (except this doesn't work) > > module Kernel >   def self.puts text, debug=false >     $stdout.puts text if debug >   end > end > > puts "Hello, World!", true > > Any ideas? > -- > Posted viahttp://www.ruby-forum.com/. You're creating a new Kernel.puts module method; you want to redefine the Kernel#puts instance method.