Skip to content

Instantly share code, notes, and snippets.

@yelinaung
Created January 8, 2014 11:45
Show Gist options
  • Save yelinaung/8315673 to your computer and use it in GitHub Desktop.
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
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")
@indexer
Copy link

indexer commented Jan 8, 2014

:D very good that is help me in learning Ruby :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment