Created
January 8, 2014 11:45
-
-
Save yelinaung/8315673 to your computer and use it in GitHub Desktop.
Overloading in Ruby is not real "Overloading" because there is no data type declaration in ruby(dynamic typed language) . Ref : http://stackoverflow.com/questions/9373104/why-does-ruby-not-support-method-overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def say_hello(name) | |
puts "Hi #{name}" | |
end | |
# say_hello("devlabs") | |
def say_hello(name,age) | |
puts "Hi #{name} and your age is\n" | |
puts age | |
end | |
# say_hello("yelinaung",21) | |
def say_hello(a,b) | |
puts a + b | |
end | |
# say_hello(20,11) | |
def say_hello(a,b,c) | |
x = [a,b,c] | |
x.each do |y| | |
puts y | |
end | |
end | |
# say_hello(1,2,3) | |
# say_hello("yelinaung",2,3) | |
def say_hello(mFloat) | |
# return is unnecessary here | |
# because ruby always return the last value | |
return 1.0 + mFloat | |
end | |
# say_hello(2.0) | |
def say_hello(mArray) | |
mArray.each do |x| | |
puts "Hi #{x}" | |
end | |
end | |
# i = [1,2,3,4,5] | |
# say_hello(i) | |
# Level 6 :P | |
def say_hello(*args) | |
a = [] | |
a.push(*args) | |
a.each do |x| | |
puts x | |
end | |
end | |
# say_hello(1,2,4,5,5,6,7,"yelinaung") | |
# say_hello("yemonkyaw", "bromance", 1,3,2.0,333333, "yelinaung") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:D very good that is help me in learning Ruby :D