Class: Ribbon::Options
- Inherits:
- BasicObject
- Defined in:
- lib/ribbon/options.rb
Overview
Applies options to all method calls.
Ribbon::Options.new(object, option: :value) do
method_with some: :settings # equivalent to { some: :settings, option: :value }
overrides option: { with: :another_value }
end
Ribbon::Options.apply_to(Ribbon.new, separator: '->') do |ribbon|
ribbon.to_s
ribbon.inspect
end
Instance Method Summary collapse
-
#initialize(receiver, options = {}, &block) ⇒ Options
constructor
Applies the given options to all methods sent to the receiver.
-
#method_missing(method, *arguments, &block) ⇒ Object
Merges the options given to the method with the options associated with this instance and sends the method to the receiver as normal.
Constructor Details
#initialize(receiver, options = {}, &block) ⇒ Options
Applies the given options to all methods sent to the receiver. Will apply the block immediately, if given one.
33 34 35 36 |
# File 'lib/ribbon/options.rb', line 33 def initialize(receiver, = {}, &block) @receiver, @options = receiver, __yield_or_eval__ &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
Merges the options given to the method with the options associated with this instance and sends the method to the receiver as normal.
40 41 42 43 44 |
# File 'lib/ribbon/options.rb', line 40 def method_missing(method, *arguments, &block) = arguments. arguments << ::Ribbon.deep_merge(@options, ) @receiver.__send__ method, *arguments, &block end |