free_mutant/lib/mutant/delegator.rb

47 lines
801 B
Ruby
Raw Normal View History

2014-05-11 13:20:09 -04:00
module Mutant
module Delegator
module ClassMethods
private
2014-05-22 22:57:43 -04:00
2014-05-11 13:20:09 -04:00
# Create delegators to object
#
# @return [undefined]
#
# @api private
#
def delegate(*names)
2014-05-22 23:47:50 -04:00
names.each(&method(:define_delegator))
2014-05-11 13:20:09 -04:00
end
# Create delegator to object
#
# @param [Symbol] name
#
# @return [undefined]
#
# @api private
#
def define_delegator(name)
define_method(name) do
object.public_send(name)
end
private name
end
end # ClassMethods
# Hook called when module is included
#
# @param [Class,Module] host
#
# @api private
#
def self.included(host)
super
2014-05-22 23:49:20 -04:00
host.extend(ClassMethods)
2014-05-11 13:20:09 -04:00
end
end # Delegator
end # Mutant