You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ ruby -v
jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 +jit [darwin-x86_64]
$ cat test.rb
require 'irb/ruby-lex'
RubyLex.new.each_top_level_statement do |s, linenum|
puts s
end
$ echo "foo" | ruby test.rb
NoMethodError: undefined method `encoding' for #<IO:<STDIN>>
Did you mean? set_encoding
block in each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:245
loop at org/jruby/RubyKernel.java:1298
block in each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:232
catch at org/jruby/RubyKernel.java:1120
each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:231
<main> at test.rb:2
I guess you can say we are bug for bug compatible!
echo "foo" | mri23 ../snippets/lex1.rb
/home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement': undefined method `encoding' for #<IO:<STDIN>> (NoMethodError)
Did you mean? set_encoding
from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop'
from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch'
from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
from ../snippets/lex1.rb:2:in `<main>'
Can you perhaps open up an issue on ruby-lang.org and see what they say? I see this present in 2.3 and 2.4 so I am guessing perhaps you are the first person to try this?
Did a little analysis on this and talked on IRC and it looks like the issue is that ruby-lex.rb uses 'io' as a variable but it does not really work with an IO since IO has no .encoding method. It seems to use a subclass of InputMethod (which has the missing .encoding method). So my conclusion is that naming is confusing and there is no bug here; but perhaps there could be some better documentation in ruby-lex.rb
https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/irb/ruby-lex.rb#L245 might need to be
@io.external_encoding
?The text was updated successfully, but these errors were encountered: