https://github.com/srghma/require_module
Evaluates file content inside Module.new, with cache
https://github.com/srghma/require_module
Last synced: 7 months ago
JSON representation
Evaluates file content inside Module.new, with cache
- Host: GitHub
- URL: https://github.com/srghma/require_module
- Owner: srghma
- License: mit
- Created: 2018-01-12T09:22:30.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-29T08:20:00.000Z (over 7 years ago)
- Last Synced: 2025-05-23T14:47:03.655Z (8 months ago)
- Language: Ruby
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# require_module
[](https://travis-ci.org/BjornMelgaard/require_module)
[](https://badge.fury.io/rb/require_module)
Evaluates file content inside Module.new, with cache
# Install
```rb
gem 'require_module'
```
# API
## require_module(fullpath)
Evaluates file content inside Module.new and returns new module
```rb
require_module('/home/user/rubyapp/lib', cache: false) # returns #
require_module('/home/user/rubyapp/lib') # returns :HomeUserRubyappLib
```
## require_module_relative(relative_path)
Similar to "require_module", but path is relative to file, where function is executed
Check `lib/require_module.rb` for more
# Example
If you don't want you modules to intersect, they should have unique name.
I was tired of coming up with new names, so created this gem.
Instead of
```rb
# lib.rb
module GloballyUniqueName
module_function
def somefn
'Ima helper'
end
end
```
```rb
# consumer.rb
require_relative './lib'
module Consumer
include GloballyUniqueName
def foo
somefn == 'Ima helper'
end
end
```
You can write this
```rb
# lib.rb
module_function
def somefn
'Ima helper'
end
```
```rb
# consumer.rb
module Consumer
include require_module_relative('./lib')
def foo
somefn == 'Ima helper'
end
end
```