Project

use

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
The use library solves the multi-mixin problem by allowing you to selectively mixin specific methods from a module rather than mixing in all of them. In addition, you can alias methods on the fly as they are mixed in, effectively allowing you to change the name of the mixin method.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

Notice

Please do not confuse "use" with "using". This library was written before refinements existed in Ruby, and it is largely obviated by that feature now. Consequently I have archived this repository as I don't see a compelling case for its usage any longer.

Description

The 'use' library allows you to selectively mixin methods from a given module and alias them on the fly if desired.

Prerequisites

structured_warnings 0.3.0 or later

Installation

gem install use

Synopsis

require 'use'
 
module Foo
  def bar
    puts "hello"
  end
  def baz
    puts "world"
  end
end

module Test
  def bar
    puts "goodbye"
  end
  def blah
    puts "new york"
  end
end

class Zap
  use Foo, :bar
  use Test, :blah
end

z = Zap.new

z.bar  # => "hello"
z.blah # => "new york"
z.baz  # => NoMethodError
 
# Using the new keywords
class MyKlass
  use Foo, :alias => {:bar => :test}
end
 
m = MyKlass.new
m.test # => "hello"
m.bar  # => NoMethodError

Constants

USE_VERSION

The version of this library. This is a string.

Notes

In $VERBOSE mode this library will issue a MethodRedefinedWarning if you shadow an existing method. See the documentation for structured_warnings for more details.

Acknowledgements

Thanks go to Ara Howard for providing the original solution and to Mauricio Fernandez, whose blog I plagiarized (and with whom I communicated) in order to implement fine-grained mixins.

Known Bugs

Some versions of Ruby 1.9.x may emit a warning in verbose mode. This is a bug in Ruby 1.9.x and can be ignored. I seriously hope you aren't using Ruby 1.9 at this point.

See Also

mixology at https://github.com/dan-manges/mixology

Future Plans

None. Please see the Notice at the top.

License

Apache-2.0

Copyright

(C) 2005-2019, Daniel J. Berger All Rights Reserved

Author

Daniel J. Berger