Skip to content

$stdout set to an object with only #write breaks puts and print #134

Closed

Description

@Largo

Setting $stdout to an object that only implements #write (a logger, a capture object) breaks puts and print:

class W; def write(*x) = $stderr.write("[#{x.join}]"); end
$stdout = W.new
puts 'foo'
print "bar\n"
# CRuby:    [foo\n][bar\n]
# IronRuby: private method 'puts' called for an instance of W (NoMethodError)

CRuby's Kernel#puts calls $stdout.puts only when it is public. Otherwise it formats the lines itself and calls #write (rb_io_puts through rb_io_writev), and $stdout= only requires #write.

Found by running the scripts PR #119 deleted (Tests/Experiments, Tests/Legacy) on CRuby 4.0.9 and on IronRuby built from master c7f70cf (net10.0, Linux). (Experiments/Globals/Stdout.rb)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions