Module: TypeWrapper
- Defined in:
- lib/type_wrapper.rb,
lib/type_wrapper/module.rb,
lib/type_wrapper/version.rb
Defined Under Namespace
Classes: Module
Constant Summary collapse
- FOR =
-> type, *behaviors do Class.new(Delegator) do include TypeWrapper const_set :Type, type const_set :BEHAVIORS, behaviors const_set :Trait, Module.new { behaviors.each { |mod| include mod.refines(type) } } forwarding = behaviors.flat_map(&:public_instance_methods) - public_instance_methods code = forwarding.uniq.map { |meth| "def %{meth}(*args, &block) __getobj__.%{meth}(*args, &block) end" % { meth: meth } } class_eval code.unshift("using Trait").join("\n") end end
- VERSION =
"1.2.0".freeze
Class Method Summary collapse
Class Method Details
.[](*types) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/type_wrapper.rb', line 14 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 FOR[*types] end |