J
Jack Christensen
What's the difference between defining a class inside of a module and
using the module as a prefix?
module Foo
class Bar
end
end
module Foo
class Works
def f
Bar.new
end
end
end
class Foo::Fails
def f
Bar.new
end
end
Foo::Works.new.f
Foo::Fails.new.f
The last line fails:
lookup.rb:16:in `f': uninitialized constant Foo::Fails::Bar (NameError)
from lookup.rb:21
I would have thought that both ways of placing a class in a module would
be equivalent.
Thanks.
Jack
using the module as a prefix?
module Foo
class Bar
end
end
module Foo
class Works
def f
Bar.new
end
end
end
class Foo::Fails
def f
Bar.new
end
end
Foo::Works.new.f
Foo::Fails.new.f
The last line fails:
lookup.rb:16:in `f': uninitialized constant Foo::Fails::Bar (NameError)
from lookup.rb:21
I would have thought that both ways of placing a class in a module would
be equivalent.
Thanks.
Jack