10
जब मैं कोड को चलाने के नीचे यह त्रुटि बढ़ा:मैं ओवरलोडिंग विधि के साथ define_method में सुपर क्यों नहीं कह सकता?
implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (RuntimeError).
मुझे यकीन है कि समस्या यह है कि क्या नहीं कर रहा हूँ।
class Result
def total(*scores)
percentage_calculation(*scores)
end
private
def percentage_calculation(*scores)
puts "Calculation for #{scores.inspect}"
scores.inject {|sum, n| sum + n } * (100.0/80.0)
end
end
def mem_result(obj, method)
anon = class << obj; self; end
anon.class_eval do
mem ||= {}
define_method(method) do |*args|
if mem.has_key?(args)
mem[args]
else
mem[args] = super
end
end
end
end
r = Result.new
mem_result(r, :total)
puts r.total(5,10,10,10,10,10,10,10)
puts r.total(5,10,10,10,10,10,10,10)
puts r.total(10,10,10,10,10,10,10,10)
puts r.total(10,10,10,10,10,10,10,10)
धन्यवाद: आप जब आप इसे
define_method
ब्लॉक के अंदर फोन स्पष्ट रूप सेsuper
तर्क पारित करने के लिए की जरूरत है। यह एक आकर्षण की तरह काम कर रहा है। –