Code Monkey home page Code Monkey logo

require_module's Introduction

require_module

Build Status Gem Version

Evaluates file content inside Module.new, with cache

Install

gem 'require_module'

API

require_module(fullpath)

Evaluates file content inside Module.new and returns new module

require_module('/home/user/rubyapp/lib', cache: false) # returns #<Module:0000012312>
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

# lib.rb
module GloballyUniqueName
  module_function

  def somefn
    'Ima helper'
  end
end
# consumer.rb
require_relative './lib'

module Consumer
  include GloballyUniqueName

  def foo
    somefn == 'Ima helper'
  end
end

You can write this

# lib.rb
module_function

def somefn
  'Ima helper'
end
# consumer.rb
module Consumer
  include require_module_relative('./lib')

  def foo
    somefn == 'Ima helper'
  end
end

require_module's People

Contributors

angelinatarapko avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.