From: Charles Oliver Nutter Date: 2010-04-30T11:36:18+09:00 Subject: Re: Use of STDOUT.flush after puts On Thu, Apr 29, 2010 at 4:24 PM, Caleb Clausen wrote: > On 4/29/10, hemant wrote: >> How can reopen change the class btw? Ruby is not a class oriented language >> btw. > > Check out this code. No other method in all of ruby has this behavior. > >  p $stderr.class #=>IO > >  f=File.new "foo","w" >  $stderr.reopen(f) > >  p $stderr.class #=>File This is a really nasty feature not a lot of people know about. It's not possible for us to support in JRuby because the underlying object can't actually change class: ~/projects/jruby ➔ jruby -rjruby -e 'p JRuby.reference($stdout).class' Java::OrgJruby::RubyIO ~/projects/jruby ➔ jruby -rjruby -e 'p JRuby.reference(File.open("build.xml")).class' Java::OrgJruby::RubyFile Arbitrary IO objects are org.jruby.RubyIO objects behind the scenes, while files are RubyFile (< RubyIO) and sockets are RubySocket (< RubyIO) or one of its subclasses. "Becoming" another class isn't an option. The closest we could probably come would be to change the .class to a common superclass of both actual types, but that's still pretty goofy. I'm of the opinion that .reopen should be discouraged in general. - Charlie