irb のトップレベルで定義したメソッドが public になる
irb のトップレベルで定義したメソッドの呼び出し制限が private ではなく public になってしまいます。
irb(main):001:0> def greeting
irb(main):004:0> val = Object.new
irb(main):006:0> val.private_methods.grep /greeting/
irb(main):007:0> val.public_methods.grep /greeting/
public になるのは irb で実行したときのみです（ファイルに保存して ruby コマンドで実行した場合は private メソッドとして定義されます）。
- lib/irb/workspace.rb: define method to private on top-level irb [Bug #5776]. Patch by davidbalbert.
#2 [ruby-dev:45856] Updated by David Albert over 3 years ago
I ran into this bug recently and I did a bit of investigating. This is due to a change introduced by #3406 (r29578) that made inner method definitions public regardless of the visibility of the method they were defined in.
I've attached a patch that calls
private in the
irb_binding method before returning the binding, which fixes the problem. I also verified that context mode 3 was the only mode affected by r29578 and that IRB works correctly when started via the command line and via
#3 Updated by Keiju Ishitsuka about 3 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100