Ruby Issue Tracking System: Issueshttps://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-02-28T21:03:50ZRuby Issue Tracking System
Redmine Ruby master - Bug #9580 (Closed): Refinements regression in IRBhttps://redmine.ruby-lang.org/issues/95802014-02-28T21:03:50Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>The problem: Top level refinements do not work in IRB. They worked in 2.0.0-p451, but don't work in 2.1.0, 2.1.1, or today's trunk.</p>
<p>Details:</p>
<p>Here some code in a file:</p>
<pre><code>#refine.rb
module A
refine String do
def asdf
:asdf
end
end
end
using A
p "foo".asdf
</code></pre>
<p>In all versions, of Ruby between 2.0.0-p451 and 2.2.0dev, running this file, prints <code>:asdf</code>. This is the expected behavior. Ruby 2.0.0 also prints the "Refinements are experimental" warning, as expected:</p>
<pre><code># Ruby 2.0.0-p451
$ ruby refine.rb
refine.rb:2: warning: Refinements are experimental, and the behavior may change in future versions of Ruby!
:asdf
# Ruby 2.1.0, 2.1.1, and 2.2.0dev
$ ruby refine.rb
:asdf
</code></pre>
<p>In Ruby 2.0.0-p451, the same code also works in IRB, also as expected:</p>
<pre><code>irb(main):001:0> "#{RUBY_VERSION}-#{RUBY_PATCHLEVEL}"
=> "2.0.0-451"
irb(main):002:0> module A
irb(main):003:1> refine String do
irb(main):004:2* def asdf
irb(main):005:3> :asdf
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
(irb):3: warning: Refinements are experimental, and the behavior may change in future versions of Ruby!
=> #<refinement:String@A>
irb(main):009:0> using A
=> main
irb(main):010:0> "foo".asdf
=> :asdf
</code></pre>
<p>However, in all newer versions of Ruby (2.1.0, 2.1.1, and 2.2.0dev), this code raises a <code>NoMethodError</code> in IRB:</p>
<pre><code>irb(main):001:0> RUBY_VERSION
=> "2.1.0"
irb(main):002:0> module A
irb(main):003:1> refine String do
irb(main):004:2* def asdf
irb(main):005:3> :asdf
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
=> #<refinement:String@A>
irb(main):009:0> using A
=> main
irb(main):010:0> "foo".asdf
NoMethodError: undefined method `asdf' for "foo":String
from (irb):10
from out/bin/irb:11:in `<main>'
irb(main):001:0> RUBY_VERSION
=> "2.1.1"
irb(main):002:0> module A
irb(main):003:1> refine String do
irb(main):004:2* def asdf
irb(main):005:3> :asdf
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
=> #<refinement:String@A>
irb(main):009:0> using A
=> main
irb(main):010:0> "foo".asdf
NoMethodError: undefined method `asdf' for "foo":String
from (irb):10
from bin/irb:11:in `<main>'
irb(main):001:0> RUBY_VERSION
=> "2.2.0"
irb(main):002:0> module A
irb(main):003:1> refine String do
irb(main):004:2* def asdf
irb(main):005:3> :asdf
irb(main):006:3> end
irb(main):007:2> end
irb(main):008:1> end
=> #<refinement:String@A>
irb(main):009:0> using A
=> main
irb(main):010:0> "foo".asdf
NoMethodError: undefined method `asdf' for "foo":String
from (irb):10
from bin/irb:11:in `<main>'
</code></pre>
<p>This seems like a bug because the code behaves differently in IRB than how it behaves in the file. If it's the intended behavior, it's frustrating because it makes it harder to prototype code that uses refinements in the REPL.</p>
<p>This issue is not specific to IRB. I get the same behavior in Pry (works in 2.0.0, doesn't work in newer Ruby versions). This makes me think the issue is not inside the IRB source, but rather has something to do with <code>using</code>'s behavior in the <code>Binding</code> objects that IRB and Pry are probably using. I haven't looked at the Pry or IRB source in quite a long time, so this paragraph is mostly speculation.</p>
<p>Please let me know if there's any more info I can provide to make this easier to fix</p> Ruby master - Bug #7859 (Closed): Readline: Incorrect arrow key behavior in vi_editing_mode inser...https://redmine.ruby-lang.org/issues/78592013-02-16T04:20:20Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>=begin<br>
I've discovered what I think is a bug in the (({Readline})) module in the standard library. When I am using (({vi_editing_mode})) in insert mode (rather than command mode), I am unable to use the up arrow to go up through history. It seems that I can only go up through history when in command mode. Additionally, pressing the down arrow while in insert mode changes to command mode, which seems odd.</p>
<p>Perhaps this is intended behavior for the (({Readline})) module, but if it is, I would propose changing it. I would expect the up and down arrows to scroll up and down through history in both command mode and insert mode when (({Readline.vi_editing_mode?})) is true. You can find examples of the expected behavior in bash (<code>((%set -o vi%))</code> to get into vi mode), the Python REPL, and all other that I can remember using.</p>
<p>I've reproduced this with (({Readline})) 6.2 on Mac OS X 10.8.2 and Ubuntu precise64 with kernel version 3.2.0-37. It is worth noting that on Mac OS X with the EditLine wrapper, the (({Readline})) module works correctly although you must have the proper settings in your .editrc file because (({Readline.vi_editing_mode})) is not implemented.</p>
<p>Here is the code I used to test:</p>
<a name="readlinetestrb"></a>
<h1 >readlinetest.rb<a href="#readlinetestrb" class="wiki-anchor">¶</a></h1>
<p>require 'readline'</p>
<p>trap(:INT) {<br>
exit 0<br>
}</p>
<p>Readline.vi_editing_mode<br>
puts "Readline::VERSION => #{Readline::VERSION}"</p>
<p>loop do<br>
puts Readline.readline(">> ", true)<br>
end</p>
<p>Example usage:</p>
<p>$ ruby readlinetest.rb<br>
Readline::VERSION => 6.2</p>
<blockquote>
<blockquote>
<p>1234<br>
1234</p>
</blockquote>
</blockquote>
<p>At this point, I would expect that the up arrow would put 1234 after the prompt, but instead nothing happens. Pressing the down arrow is the same as pressing escape and changes (({readline})) into command mode.</p>
<p>Let me know if there's anything else I can provide to help fix this. I tried jumping into the (({Readline})) module myself, but I'm not particularly familiar with how (({readline})) works and wasn't able to make much headway.<br>
=end</p> Ruby master - Bug #7794 (Closed): Documentation bug in Net::HTTP.post_form example codehttps://redmine.ruby-lang.org/issues/77942013-02-07T09:18:52Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>I've attached a patch that fixes a small error in the Net::HTTP.post_form documentation.</p> Ruby master - Bug #7105 (Closed): Socket documentation fixhttps://redmine.ruby-lang.org/issues/71052012-10-04T06:55:01Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>The "Quick start" section of the Socket documentation refers to the Socket::INET constant, which doesn't exist. I've attached a small patch changing the reference to Socket::AF_INET, which seems consistent with the rest of the documentation (the alternative would be Socket::PF_INET, which has the same value).</p> Ruby master - Bug #6786 (Closed): Add :trace_instruction to the output of RubyVM::InstructionSequ...https://redmine.ruby-lang.org/issues/67862012-07-24T13:17:37Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>:trace_instruction is a valid iseq compiler option that can be set with compile_option=, but it does not appear in the hash returned by RubyVM::InstructionSequence.compile_option. I've attached a patch that fixes this.</p> Ruby master - Bug #6785 (Closed): Documentation for RubyVM::InstructionSequencehttps://redmine.ruby-lang.org/issues/67852012-07-24T12:57:42Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>I've attached a patch with documentation for the RubyVM::InstructionSequence class. It's of decent size, and I'm just getting familiar with the VM, so please send comments and corrections if you have any. I'm happy to do further passes if need be.</p> Ruby master - Bug #6750 (Closed): Comment above rb_iseq_struct.local_size gives out of date descr...https://redmine.ruby-lang.org/issues/67502012-07-18T07:13:12Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>The description of rb_iseq_struct.local_size says that it is sizeof(local vars) + 1 for class and method frames, but just sizeof(local vars) for block frames. I think this is no longer the case. local_size is always sizeof(local vars) + 1.</p>
<p>Here's the relevant code from when the comment was written (2007): <a href="https://github.com/ruby/ruby/blob/71986ef6bc232455deca67017873fff0c3cbd860/compile.c#L5004-5010" class="external">https://github.com/ruby/ruby/blob/71986ef6bc232455deca67017873fff0c3cbd860/compile.c#L5004-5010</a><br>
And here's the code today: <a href="https://github.com/ruby/ruby/blob/trunk/compile.c#L5571" class="external">https://github.com/ruby/ruby/blob/trunk/compile.c#L5571</a></p>
<p>I've attached a patch that fixes the comment.</p> Ruby master - Bug #6475 (Closed): Fix decryption example in OpenSSL docshttps://redmine.ruby-lang.org/issues/64752012-05-21T02:16:57Zdavidbalbert (David Albert)davidbalbert@gmail.com
<p>The code example in the "Decryption" section of the OpenSSL docs shows ciphertext being decrypted with the same key used to encrypt it. Instead, decryption should be done with the other key in the pair. I've verified that the sample code in trunk does not work, and the sample code in the attached patch does work.</p>