Created
May 15, 2014 19:19
-
-
Save asterite/99e6b206acd426fe2b1a to your computer and use it in GitHub Desktop.
initialize overload
This file contains hidden or 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
| class Foo | |
| def initialize(x : Number) | |
| puts "#{x} is a number!" | |
| end | |
| def initialize(x : String) | |
| puts "#{x} is a string!" | |
| end | |
| end | |
| Foo.new(1) # prints "1 is a number!" | |
| Foo.new("hello") # prints "hello is a string!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment