Re: Problem with Changing from $defout > $stdout

Shugo Maeda <[email protected]> Thu, 15 Sep 2005 00:12:02 +0900
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
Hi,

Ben Gribaudo wrote:
> I'm working on upgrading some Ruby 1.6.x to prepare for a web-server
> wide upgrade to 1.8.2 (We're still running under 1.6.x). $defout is
> obsolete in Ruby 1.8.2. In irb, $defout==$stdout, so I would think that
> I should be able to replace any usage of $defout in a script with
> $stdout. But it doesn't work!
>
> Take the code below. I would expect to be able use either "$defout =
> out" and "$defout = starting_stdout" OR "$stdout = out" and "$stdout =
> starting_stdout". However, only the $defout lines work

"$stdout = out" worked for me.

-- test.rbx -----------
def get_output
    starting_stdout = $stdout
    begin
        out = Object.new
        class << out
            attr_reader :output
            def write(value)
                @output ||= ''
                @output << value.to_s
            end
            alias << write
            def flush(*args) end
        end
        ## Either of these lines should result in the same effect, correct?
        #$defout = out
        $stdout = out
        yield
    ensure
        ## Again, these two lines are identical in function, right?
        #$defout = starting_stdout
        $stdout = starting_stdout
    end
    puts ($stdout==$defout)==false
    return out.output
end

r = Apache.request
r.content_type = "text/plain"
r.send_http_header
p get_output {
    print "foo\n"
}
-----------------------------

My environment is below.

mod_ruby/1.2.4
Ruby/1.8.3(2005-06-23)

> Interestingly, while $stdout==$defout is true in irb, it is false in
> mod_ruby as puts puts ($stdout==$defout)==false true.

$defout(rb_defout) was removed from C API of Ruby 1.8, so mod_ruby
only sets $stdout(rb_stdout) now.

Shugo