Sha256: ff5509624cb82e88638ff040059c39fb0191038d229c584f40305535aee39c7a

Contents?: true

Size: 904 Bytes

Versions: 4

Compression:

Stored size: 904 Bytes

Contents

module Eco
  module Language
    module Methods
      module DslAble
        # It runs the `block` within this object context
        # @note if the object misses any method, redirects the method to the
        #   original evaluate caller.
        def evaluate(*args, **kargs, &block)
          return unless block_given?
          @self_before_evaluate = eval "self", block.binding
          instance_exec(*args, **kargs, &block).tap do
            @self_before_evaluate = nil
          end
        end

        # When it's the case, redirect to the original `evaluate` caller
        # @see https://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
        def method_missing(method, *args, **kargs, &block)
          super unless @self_before_evaluate
          @self_before_evaluate.send(method, *args, **kargs, &block)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eco-helpers-2.6.4 lib/eco/language/methods/dsl_able.rb
eco-helpers-2.6.3 lib/eco/language/methods/dsl_able.rb
eco-helpers-2.6.2 lib/eco/language/methods/dsl_able.rb
eco-helpers-2.6.1 lib/eco/language/methods/dsl_able.rb