Skip to content

Instantly share code, notes, and snippets.

@scalp42
Created October 29, 2017 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalp42/c06281d476d2222b4715ec595c4f80cb to your computer and use it in GitHub Desktop.
Save scalp42/c06281d476d2222b4715ec595c4f80cb to your computer and use it in GitHub Desktop.
Multiple types overloading
def add(x : Number, y : Number)
x + y
end
def add(x: Number, y: String)
x.to_s + y
end
# vs
def add(x : Number, y : [Number, String])
if y.is_a?(String)
x.to_s + y
else
x + y
end
add(1, 2)
add (1, "a")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment