lib/veil.rb in veils-0.0.1 vs lib/veil.rb in veils-0.1.0
- old
+ new
@@ -46,38 +46,33 @@
return @origin.to_a.to_json(options) if @origin.is_a?(Array)
method_missing(:to_json, options)
end
def method_missing(*args)
+ method = args[0]
if @pierced
- through(args)
- else
- method = args[0]
- if @methods.key?(method)
- @methods[method]
+ unless @origin.respond_to?(method)
+ raise "Method #{method} is absent in #{@origin}"
+ end
+ if block_given?
+ @origin.__send__(*args) do |*a|
+ yield(*a)
+ end
else
- @pierced = true
- through(args)
+ @origin.__send__(*args)
end
+ elsif @methods.key?(method)
+ @methods[method]
+ else
+ @pierced = true
+ method_missing(*args)
end
end
def respond_to?(method, include_private = false)
@origin.respond_to?(method, include_private) || @methods[method]
end
def respond_to_missing?(_method, _include_private = false)
true
- end
-
- private
-
- def through(args)
- method = args[0]
- unless @origin.respond_to?(method)
- raise "Method #{method} is absent in #{@origin}"
- end
- @origin.__send__(*args) do |*a|
- yield(*a) if block_given?
- end
end
end