Project

General

Profile

Actions

Bug #11754

closed

Visibility scope is kept after lexical scope is closed

Added by printercu (Max Melentiev) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.0preview1 (2015-11-11 trunk 52539) [x86_64-darwin13]
[ruby-core:71762]

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?


Related issues 2 (1 open1 closed)

Related to Ruby master - Feature #11665: Support nested functions for better code organizationOpenActions
Related to Ruby master - Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3Closednobu (Nobuyoshi Nakada)Actions

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) :

Actions #3

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)
Actions #5

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.

Actions #6

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0