Bug #5776

irb のトップレベルで定義したメソッドが public になる

Added by hi hibariya over 3 years ago. Updated over 2 years ago.

[ruby-dev:<unknown>]
Status:Closed
Priority:Normal
Assignee:Keiju Ishitsuka
ruby -v:ruby 2.0.0dev (2011-12-15 trunk 34056) [x86_64-darwin11.2.0] Backport:

Description

irb のトップレベルで定義したメソッドの呼び出し制限が private ではなく public になってしまいます。


irb(main):001:0> def greeting
irb(main):002:1> 'hi'
irb(main):003:1> end
=> nil
irb(main):004:0> val = Object.new
=> #Object:0x007fe6ca05fd80
irb(main):005:0> val.greeting
=> "hi"
irb(main):006:0> val.private_methods.grep /greeting/
=> []
irb(main):007:0> val.public_methods.grep /greeting/

=> [:greeting]

public になるのは irb で実行したときのみです(ファイルに保存して ruby コマンドで実行した場合は private メソッドとして定義されます)。

0001-make-top-level-methods-defined-in-IRB-private.patch Magnifier (780 Bytes) David Albert, 06/27/2012 08:06 AM

Associated revisions

Revision 38597
Added by Keiju Ishitsuka over 2 years ago

  • lib/irb/workspace.rb: define method to private on top-level irb [Bug #5776]. Patch by davidbalbert.

Revision 38597
Added by Keiju Ishitsuka over 2 years ago

  • lib/irb/workspace.rb: define method to private on top-level irb [Bug #5776]. Patch by davidbalbert.

History

#1 Updated by Ayumu AIZAWA about 3 years ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to Keiju Ishitsuka
  • Target version set to 2.0.0

1.9.3-p0でも再現することを確認しました。

#2 Updated by David Albert almost 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 IRB.start.

#3 Updated by Keiju Ishitsuka over 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38597.
hi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/irb/workspace.rb: define method to private on top-level irb [Bug #5776]. Patch by davidbalbert.

Also available in: Atom PDF