Project

including

0.0
No commit activity in last 3 years
No release in over 3 years
An observation: Other languages allow for more granular loading of only desired methods and functions from module code. An experiment: How might this be done in Ruby?
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.0.0
~> 1.8.3
~> 2.8.0
 Project Readme

including¶ ↑

  • An observation: Other languages allow for more granular loading of only desired methods and functions from module code.

  • An experiment: How might this be done in Ruby?

  • A warning: Running this code in production might not be wise.

How does it work?¶ ↑

Let’s say you’ve got a module:

module Foo
  def foo
    "foo"
  end

  def bar
    "bar"
  end

  def baz
    "baz"
  end
end

And you want to mix it in to a class. But wait! the ‘foo` method might conflict with some other `foo`!

class Bar
  including Foo, except: "foo"
end

bar = Bar.new
bar.bar # "bar"
bar.foo # NoMethodError

That’s basically it. You can pass an array of ‘only` the methods you’d like to mix in, or an array of exceptions, via ‘except`.

class Quux
  including Foo, only: [:foo, :baz]
end

quux = Quux.new
quux.foo # "foo"
quux.bar # NoMethodError
quux.baz # "baz"

Installation¶ ↑

gem install including

Copyright¶ ↑

Copyright © 2012 Bryan Woods. See LICENSE.txt for further details.