File: double_definition_create_blank_slate.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (33 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module RR
  module DoubleDefinitions
    class DoubleDefinitionCreateBlankSlate
      def initialize(double_definition_create, &block) #:nodoc:
        @double_definition_create = double_definition_create
        BlankSlate.call(respond_to?(:class) ? self.class : __blank_slated_class)

        if block_given?
          if block.arity == 1
            yield(self)
          else
            respond_to?(:instance_eval) ? instance_eval(&block) : __blank_slated_instance_eval(&block)
          end
        end
      end

      if KeywordArguments.fully_supported?
        def method_missing(method_name, *args, **kwargs, &block)
          @double_definition_create.call(method_name, args, kwargs, &block)
        end
      else
        def method_missing(method_name, *args, &block)
          @double_definition_create.call(method_name, args, {}, &block)
        end
        ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
      end

      def __double_definition_create__
        @double_definition_create
      end
    end
  end
end