Sha256: f9cd41cbc89157fff090964dd8f63f37061f66c2d3ade50e5c9821bd739272df
Contents?: true
Size: 871 Bytes
Versions: 1
Compression:
Stored size: 871 Bytes
Contents
require "direction/version" # Provide a feature like the Forwardable library, # but set the return value to self. # It provides a class level "command" method to do # message forwarding. # # class SomeClass # extend Direction # # command [:name, :id] => :collaborator, [:color, :type] => :@partner # end # # This will define methods on instances that forward to the # provided receiver while enforcing encapsulation of the # relationship between objects. module Direction def command(options) method_defs = [] options.each_pair do |key, value| Array(key).map do |command_name| method_defs.unshift %{ def #{command_name}(*args, &block) #{value}.__send__(:#{command_name}, *args, &block) self end } end end self.class_eval method_defs.join(' '), __FILE__, __LINE__ end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
direction-0.0.2 | lib/direction.rb |