Module: SknUtils::Exploring::Commander
- Defined in:
- lib/skn_utils/exploring/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
56 57 58 59 60 61 62 63 64 |
# File 'lib/skn_utils/exploring/commander.rb', line 56 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
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/skn_utils/exploring/commander.rb', line 33 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
45 46 47 48 49 50 51 52 53 |
# File 'lib/skn_utils/exploring/commander.rb', line 45 def query() Commander.define_methods(self, ) do |query, accessor| %{ def #{query}(*args, &block) #{accessor}.__send__(:#{query}, *args, &block) end } end end |