Created
April 3, 2015 06:12
-
-
Save kaneshin/ddba67b502339e4f29aa to your computer and use it in GitHub Desktop.
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
| package main | |
| import "fmt" | |
| const ( | |
| GENDER_NEUTRAL = iota | |
| GENDER_MALE | |
| GENDER_FEMALE | |
| GENDER_UNKNOWN | |
| ) | |
| func genderString(gen int) string { | |
| switch gen { | |
| case GENDER_NEUTRAL: | |
| return "Neutral" | |
| case GENDER_MALE: | |
| return "Male" | |
| case GENDER_FEMALE: | |
| return "Female" | |
| } | |
| return "Unknown" | |
| } | |
| type person struct { | |
| name string | |
| gen int | |
| } | |
| func newPerson() *person { | |
| return new(person) | |
| } | |
| func (p *person) setName(name string) { | |
| p.name = name | |
| } | |
| func (p *person) setGender(gen int) { | |
| p.gen = gen | |
| } | |
| func (p person) print_() { | |
| fmt.Println(p.name, genderString(p.gen)) | |
| } | |
| func main() { | |
| p := newPerson() | |
| p.setName("kaneshin") | |
| p.setGender(GENDER_MALE) | |
| p.print_() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment