From: Phrogz Date: 2007-03-28T02:30:04+09:00 Subject: Re: How do I implement the Unix 'tee' function for $stdout? On Mar 27, 10:55 am, Larry Fast wrote: > Erik Veenstra wrote: > > ["$stdout", "$stderr"].each do |std| > > io = eval(std) > > old_write = io.method(:write) > > > class << io > > self > > end.module_eval do > > > old_write.call(text) [snip] > Last question: what does "self" do on the line below "class << io" >> class Rectangle; end => nil >> r = Rectangle.new => # >> class << r; self; end => #> The last expression in a block is the value of that block. In the above, 'self' is used to 'return' the singleton class that was opened with "class << io". Various libraries have code like: class Object def singleton_class class << self self end end end abstracting the somewhat odd notation. With this, the original code could be written as: io.singleton_class.module_eval ...