11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/obvious/obj.rb', line 11
def define method, input = {}, &block
define_method(method) do |method_input = {}|
block_input = {}
method_input.each do |k,v|
if input[k].nil?
raise ArgumentError.new "invalid input field #{k}"
end
unless v.is_a? input[k]
raise ArgumentError.new "invalid type for #{k} expected #{input[k]}"
end
end
input.each do |k,v|
if method_input[k].nil?
raise ArgumentError.new "missing input field #{k}"
end
end
self.instance_exec method_input, &block
end
end
|