Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot see a constant defined in the grandparent module if the parent class is singleton class #3575

Closed
tsahara opened this issue Apr 3, 2017 · 2 comments · Fixed by #3594
Closed

Comments

@tsahara
Copy link
Member

@tsahara tsahara commented Apr 3, 2017

I'm not sure Ruby's scoping rule allows it but it is not compatible with CRuby.

module A
  CONST = 123
  class << self
    p 1, CONST
    class B
      p 2, CONST
    end
  end
end
% ruby -v a.rb
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
1
123
2
123

% bin/mruby a.rb
1
123
trace:
	[0] a.rb:6
	[1] a.rb:5
	[2] a.rb:3
	[3] a.rb:1
a.rb:6: uninitialized constant #<Class:0x7fd92a802ce0>::B::CONST (NameError)
@ghost
Copy link

@ghost ghost commented Apr 5, 2017

Right. I guess the main-ruby behaviour may be the correct one.

(Note that the code that you showed, does not output what you added lateron, e. g. there is no 1 and no 2 output on a single line.)

@tsahara
Copy link
Member Author

@tsahara tsahara commented Apr 5, 2017

I updated the issue comment. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant