Actions
Bug #11754
closedVisibility scope is kept after lexical scope is closed
Description
module X
def self.test_def
def x; end;
end
private
def y; end;
end
X.test_def
X.instance_methods
In 2.2 it returns [:x], in 2.3-preview1 it returns empty array. Is it ok?
Updated by printercu (Max Melentiev) about 9 years ago
Better example
module X
def self.test_def(name)
define_method(name) {}
end
test_def :x
private
test_def :y
def pr; end
end
X.test_def :z
X.public_instance_methods
# 2.2.2 => [:x, :y, :z]
# 2.3-preview1 => [:x]
Updated by j15e (Jean-Philippe Doyle) about 9 years ago
- ruby -v set to ruby 2.3.0preview1 (2015-11-11 trunk 52539) [x86_64-darwin13]
To provide some context, this creates issues with two gems I am using that have dynamically defined methods (that now seems to be incorrectly private in 2.3.0preview1) :
- paranoia (
really_destroy!
method defined in https://github.com/rubysherpas/paranoia/blob/rails4/lib/paranoia.rb#L185-L190) - money (all methods defined in https://github.com/RubyMoney/money/blob/master/lib/money/money/formatting.rb#L4-L14)
Updated by mame (Yusuke Endoh) about 9 years ago
- Related to Feature #11665: Support nested functions for better code organization added
Updated by ko1 (Koichi Sasada) about 9 years ago
- Assignee set to ko1 (Koichi Sasada)
Updated by ko1 (Koichi Sasada) about 9 years ago
- Status changed from Open to Closed
Applied in changeset r52996.
-
vm.c (rb_vm_cref_in_context): Module#define_method in non-class
expression should be public.
[Bug #11754] -
test/ruby/test_method.rb: add a test.
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
- Related to Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3 added
Actions
Like0
Like0Like0Like0Like0Like0Like0