Module: Direction
- Defined in:
- lib/direction.rb,
lib/direction/version.rb
Overview
relationship between objects.
Constant Summary collapse
- VERSION =
"2.0.1"
Class Method Summary collapse
Instance Method Summary collapse
-
#command(**options) ⇒ Object
Forward messages and return self, protecting the encapsulation of the object.
-
#def_command(accessor, method_name, aliased_method_name = method_name) ⇒ Object
Create an individual command with an optional alias.
-
#query(**options) ⇒ Object
Forward messages and return the result of the forwarded message.
Class Method Details
.extended(base) ⇒ Object
21 22 23 |
# File 'lib/direction.rb', line 21 def self.extended(base) base.extend Forwardable end |
Instance Method Details
#command(**options) ⇒ Object
Forward messages and return self, protecting the encapsulation of the object
26 27 28 29 30 |
# File 'lib/direction.rb', line 26 def command(**) .each do |methods, accessor| methods.each { |method_name| def_command accessor, method_name } end end |
#def_command(accessor, method_name, aliased_method_name = method_name) ⇒ Object
Create an individual command with an optional alias
Defines the forwarding method directly rather than via Forwardable so that method names which aren’t plain identifiers – bang (reload!), predicate (ready?), setter (value=) or operator methods – are supported.
37 38 39 40 41 42 43 |
# File 'lib/direction.rb', line 37 def def_command accessor, method_name, aliased_method_name = method_name define_method aliased_method_name do |*args, **kwargs, &block| receiver = accessor.to_s.start_with?("@") ? instance_variable_get(accessor) : __send__(accessor) receiver.__send__(method_name, *args, **kwargs, &block) self end end |
#query(**options) ⇒ Object
Forward messages and return the result of the forwarded message
46 47 48 |
# File 'lib/direction.rb', line 46 def query(**) instance_delegate end |