Module: SknUtils::Commander
- Defined in:
- lib/skn_utils/commander.rb
Class Method Summary collapse
-
.define_methods(mod, options) ⇒ Object
Commander’s class method.
Instance Method Summary collapse
-
#command(options) ⇒ Object
Forward messages and return self, protecting the encapsulation of the object.
-
#query(options) ⇒ Object
Forward messages and return the result of the forwarded message.
Class Method Details
.define_methods(mod, options) ⇒ Object
Commander’s class method
55 56 57 58 59 60 61 62 63 |
# File 'lib/skn_utils/commander.rb', line 55 def self.define_methods(mod, ) method_defs = [] .each_pair do |method_names, accessor| Array(method_names).map do || method_defs.push yield(, accessor) end end mod.class_eval method_defs.join("\n"), __FILE__, __LINE__ end |
Instance Method Details
#command(options) ⇒ Object
Forward messages and return self, protecting the encapsulation of the object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/skn_utils/commander.rb', line 32 def command() Commander.define_methods(self, ) do |command, accessor| %{ def #{command}(*args, &block) #{accessor}.__send__(:#{command}, *args, &block) self end } end end |
#query(options) ⇒ Object
Forward messages and return the result of the forwarded message
44 45 46 47 48 49 50 51 52 |
# File 'lib/skn_utils/commander.rb', line 44 def query() Commander.define_methods(self, ) do |query, accessor| %{ def #{query}(*args, &block) #{accessor}.__send__(:#{query}, *args, &block) end } end end |