Module: TypeWrapper
- Defined in:
- lib/type_wrapper.rb,
lib/type_wrapper/module.rb,
lib/type_wrapper/version.rb,
lib/type_wrapper/forwarding.rb
Defined Under Namespace
Classes: Forwarding, Module
Constant Summary collapse
- VERSION =
"1.3.0".freeze
Class Method Summary collapse
Class Method Details
.[](*types) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/type_wrapper.rb', line 9 def self.[](*types) raise TypeError, "wrong argument type (expected Module(s))" if types.include?(nil) raise ArgumentError, "wrong number of arguments (given #{types.size}, expected 2+)" if types.size < 2 type, *behaviors = *types raise ArgumentError, "Module(s) has no public methods defined" if behaviors.flat_map(&:public_instance_methods).empty? Class.new DelegateClass(type) do alias_method :~@, :__getobj__ define_method(:inspect) { "#< #{self.class.name || behaviors} #{__getobj__} #>" } behaviors.each do |mod| include Forwarding.new mod.refines(type), *mod.public_instance_methods, to: :__getobj__ end end end |