S
Shuaib Zahda
Hello guys
I was trying to overload one method but it does not work like Java.
I noticed it only uses the first method that it meets.
is there any special way for overloading in ruby.
class Overloading
def sum(a, b)
return a + b
end
def sum(a, b, c)
return a + b + c
end
end
obj = Overloading.new
puts obj.sum(5, 7)
puts obj.sum(5, 6, 7)
the output
overloading.rb:13:in `sum': wrong number of arguments (2 for 3)
(ArgumentError)
from overloading.rb:13
any idea?
Regards
Shuaib
I was trying to overload one method but it does not work like Java.
I noticed it only uses the first method that it meets.
is there any special way for overloading in ruby.
class Overloading
def sum(a, b)
return a + b
end
def sum(a, b, c)
return a + b + c
end
end
obj = Overloading.new
puts obj.sum(5, 7)
puts obj.sum(5, 6, 7)
the output
overloading.rb:13:in `sum': wrong number of arguments (2 for 3)
(ArgumentError)
from overloading.rb:13
any idea?
Regards
Shuaib