125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/record_invocation/record_invocation.rb', line 125
def record_macro(method_name, &blk)
record_module.define_method(method_name) do |*args, **kwargs, &block|
parameters = method(method_name).super_method.parameters
positional_arguments = args.dup
keyword_arguments = kwargs.dup
arguments = {}
parameters.each do |type, name|
case type
when :req, :opt
if positional_arguments.any?
arguments[name] = positional_arguments.shift
end
when :rest
if positional_arguments.any?
arguments[name] = positional_arguments
end
when :key, :keyreq
if keyword_arguments.key?(name)
arguments[name] = keyword_arguments.delete(name)
end
when :keyrest
arguments[name] = keyword_arguments
when :block
if not block.nil?
arguments[name] = block
end
end
end
invocation = Invocation.new(method_name, arguments)
__record(invocation)
super(*args, **kwargs, &block)
end
end
|