Reputation: 2233
Is there a way in ruby to load a module containing many classes and be able to access these classes without prefixing them with the module name? Consider foo.rb and bar.rb:
foo.rb:
require 'bar'
bar = BarModule::Bar.new()
bar.rb
module BarModule
class Bar
end
end
Basically I'd like the ability, from foo.rb, to refer to the class "Bar" without specifying its module every time I reference it. In java terms, I'm looking for something akin to:
import BarModule.*;
Anything like that exist?
Upvotes: 7
Views: 1733
Reputation: 237010
Modules can be mixed in to one another. To use BarModule as a mixin, you want to include BarModule
.
Upvotes: 6