Created
May 23, 2012 08:50
-
-
Save minikomi/2773983 to your computer and use it in GitHub Desktop.
Reusing base types with new methods #golang
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
var numText = "zero one two three four five six seven eight nine ten" | |
var numRoman = "- I II III IV V VI VII IX X" | |
var aText = strings.Split(numText, " ", 0) | |
var aRoman = strings.Split(numRoman, " ", 0) | |
type TextNumber int | |
type RomanNumber int | |
func (n TextNumber) String() string { | |
return aText[n]; | |
} | |
func (n RomanNumber) String() string { | |
return aRoman[n]; | |
} | |
func main() { | |
var i = 5; | |
fmt.Println("Number: ", i, TextNumber(i), RomanNumber(i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment