Created
October 21, 2012 21:25
-
-
Save patmaddox/3928556 to your computer and use it in GitHub Desktop.
James Ladd OO discussion
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 Animal | |
| def initialize(type) | |
| @type = type | |
| end | |
| def speak | |
| if @type == :cow | |
| "moo" | |
| elsif @type == :dog | |
| "woof" | |
| elsif @type == :sparrow | |
| "african or european?" | |
| end | |
| end | |
| end |
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 Animal | |
| SPEECH_TYPES = {:cow => "moo", :dog => "woof", :sparrow => "african or european?"} | |
| def initialize(type) | |
| @type = type | |
| end | |
| def speak | |
| SPEECH_TYPES[@type] | |
| end | |
| end |
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 Animal | |
| SPEECH_TYPES = {:cow => "moo", :dog => "woof", :sparrow => "african or european?"} | |
| MOVEMENT_TYPES = {:cow => "walk", :dog => "run", :sparrow => "fly"} | |
| def initialize(type) | |
| @type = type | |
| end | |
| def speak | |
| SPEECH_TYPES[@type] | |
| end | |
| def move | |
| MOVEMENT_TYPES[@type] | |
| end | |
| end |
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 Animal | |
| def self.new_cow | |
| new "moo", "walk" | |
| end | |
| def self.new_dog | |
| new "woof", "run" | |
| end | |
| def self.new_sparrow | |
| new "african or european?", "fly" | |
| end | |
| def initialize(speech, movement) | |
| @speach = speech | |
| @movement = movement | |
| end | |
| def speak | |
| @speach | |
| end | |
| def move | |
| @movement | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment