Calling IO.console twice raises NoMethodError for `#open?` #3530

Closed
hobodave opened this Issue Dec 10, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@hobodave

Code to reproduce:

IO.console # #<File:/dev/tty>
IO.console
NoMethodError: undefined method `open?' for #<File:/dev/tty>
    from /Users/davida/.rvm/rubies/jruby-9.0.4.0/lib/ruby/stdlib/io/console.rb:159:in `console'
    from (irb):2:in `<eval>'

In order to use the console returned by IO.console you have to store a reference to it:

# Explodes
IO.console.winsize # [60, 120]
IO.console.winsize 

# Works
c = IO.console
c.winsize # [60, 120]

# Also works
IO.console
IO.instance_variable_get(:@console).winsize
@kml

This comment has been minimized.

Show comment
Hide comment
@kml

kml Dec 10, 2015

Problem is in line:
https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/io/console.rb#L159

Fix did not helped: 94423c4

>> con = File.open('/dev/tty', 'r+') # or just File.new("test.txt", "w")
=> #<File:/dev/tty>
>> con.kind_of?(File)
=> true
>> con.kind_of?(IO)
=> true
>> con.open?
NoMethodError: undefined method `open?' for #<File:/dev/tty>
    from (irb):10:in `<eval>'
    from org/jruby/RubyKernel.java:978:in `eval'
    from org/jruby/RubyKernel.java:1291:in `loop'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from ~/.rvm/rubies/jruby-9.0.4.0/bin/irb:13:in `<top>'

kml commented Dec 10, 2015

Problem is in line:
https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/io/console.rb#L159

Fix did not helped: 94423c4

>> con = File.open('/dev/tty', 'r+') # or just File.new("test.txt", "w")
=> #<File:/dev/tty>
>> con.kind_of?(File)
=> true
>> con.kind_of?(IO)
=> true
>> con.open?
NoMethodError: undefined method `open?' for #<File:/dev/tty>
    from (irb):10:in `<eval>'
    from org/jruby/RubyKernel.java:978:in `eval'
    from org/jruby/RubyKernel.java:1291:in `loop'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from ~/.rvm/rubies/jruby-9.0.4.0/bin/irb:13:in `<top>'

@kares kares added the stdlib label Jan 15, 2016

@kares kares added this to the JRuby 9.0.5.0 milestone Jan 15, 2016

@kares kares closed this in 343f2a9 Jan 15, 2016

@hobodave

This comment has been minimized.

Show comment
Hide comment

hobodave commented Feb 2, 2016

Thanks!

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