Project

require3

0.0
No commit activity in last 3 years
No release in over 3 years
Kernel#require something and make its contents accessible via a different namespace.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.8
~> 5.0
>= 0

Runtime

>= 0
 Project Readme

require3

Kernel#require something and make its contents accessible via a different namespace.

Build Status

Usage

require "require3"  # Oh the irony

Now load the desired files and specify some rules:

require3 "some/very/long/name/here" => "*"

This will make everything accessible via the top-level namespace. It's the same as:

require "some/very/long/name/here"
include Some::Very::Long::Name::Here

Or access it as Foo:

require3 "some/very/long/name/here" => "foo"

Same as:

require "some/very/long/name/here"
Foo = Some::Very::Long::Name::Here

If you only want to access Foo and Bar:

require3 "some/very/long/name/here" => %w[foo bar]

Same as:

require "some/very/long/name/here"
Foo = Some::Very::Long::Name::Here::Foo
Bar = Some::Very::Long::Name::Here::Bar

You can also provide the names as Symbols and/or using their proper case:

require3 "some/very/long/name/here" => [:Foo, "Bar"]

Use a Hash to specify alternate names:

require3 "some/very/long/name/here" => { :foo => "foo_hoo", :bar => "BarHar" }

Same as:

require "some/very/long/name/here"
FooHoo = Some::Very::Long::Name::Here::Foo
BarHar = Some::Very::Long::Name::Here::Bar

Or:

require3 "some/very/long/name/here" => { "Some::Very::Foo" => "foo", :bar => "BarHar" }

Same as:

require "some/very/long/name/here"
Foo = Some::Very::Foo
BarHar = Some::Very::Long::Name::Here::Bar

require3 mostly behaves like Kernerl#require but, if what you want to alias does not exist, a NameError will be raised.

Path names are converted to class names using the same rules as Rails' String#camelize (though this library is not a dependency). If this conversion fails you must explicitly provide the name. A convoluted example:

# This fails as we try to alias Net::Http
require3 "net/http" => "n"

# Do this instead
require3 "net/http" => { "Net::HTTP" => "n" }

See Also

  • aliased - The Perl module that served as inspiration
  • Modulation - Add explicit import and export declarations to your code
  • class2 - Easily create hierarchies that support nested attributes, type conversion, serialization and more
  • alias2 - Make classes, modules, and constants accessible via a different namespace.

Author

Skye Shaw [skye.shaw AT gmail]

License

Released under the MIT License: http://www.opensource.org/licenses/MIT