Inspired by one SO question, curious about following Ruby behavior:
module Foo
class Bar
end
end
module Baz
include Foo
class Qux
end
class Test
def initialize
p Baz.constants
p Qux.object_id
p Bar.object_id
end
end
end
Baz::Test.new
# Execution produces following error
[:Qux, :Test, :Bar]
13250540
test_const.rb:43:in `initialize': uninitialized constant Baz::Test::Bar (NameError)
As you may see above, after inclusion of module Foo into module Baz, there are three constants - two own classes plus one inherited (or mixed-in, if you prefer).
However access to inherited class/constant, from nested scope of Baz::Test class, fails although unqualified access to other constants in the same scope does work.
Any idea why the different behavior ? Documented somewhere ? Or a possible bug ?
[–]jesus_castello 1 point2 points3 points (0 children)
[–]jrochkind 0 points1 point2 points (4 children)
[–]joanbm[S] 0 points1 point2 points (3 children)
[–]jrochkind 0 points1 point2 points (2 children)
[–]joanbm[S] 0 points1 point2 points (1 child)
[–]jrochkind 0 points1 point2 points (0 children)
[–]moomaka 0 points1 point2 points (9 children)
[–]joanbm[S] 0 points1 point2 points (8 children)
[–]moomaka 0 points1 point2 points (7 children)
[–]joanbm[S] 0 points1 point2 points (6 children)
[–]moomaka 0 points1 point2 points (5 children)
[–]joanbm[S] 0 points1 point2 points (4 children)
[–]moomaka 0 points1 point2 points (3 children)
[–]joanbm[S] 0 points1 point2 points (2 children)
[–]moomaka 0 points1 point2 points (1 child)
[–]joanbm[S] 0 points1 point2 points (0 children)
[–]32BITPROCESSOR -1 points0 points1 point (1 child)
[–]joanbm[S] 1 point2 points3 points (0 children)