= Namespaces for ruby
It is an experiment to bring namespaces to ruby. It is not quite clear yet why this would be useful, but it can be interesting nonetheless.
This system is inspired by the CommonJS and Python module systems, adapted for the ruby particularities.
By loading the .rb files into a temporary module, it is possible to avoid polluting the global namespace and select what to import in the current module.
Features:
Unfeatures:
class X; <<here>>; end
== Usage
See: +Namespace.open+
m = Namespace.open("hello::world")
m.hello
#=> "hello world"
In the context of "hello/world.rb" Namespace#import is made available as a shortcut.
X = import "another::module"
def hello
X::Joiner.new("hello", "world").to_s
end
Classes and modules are also exported:
class Joiner
def initialize(*a)
@args = a
end
def to_s
@args.join(' ')
end
end
== TODO
== Tricks
A module can emulate the main object behavior by extending itself. In that way, it makes it's functions directly available to consumption.
module X
extend self
def test
"x"
end
test #=> "x"
end
TODO
== Bikeshed
== Licence
Public domain
Cheers, Jonas