Created
June 18, 2012 19:09
-
-
Save Poincare/2950128 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
| class Robot | |
| def initialize | |
| @coordinates = [0, 0] | |
| @fired_at = [] | |
| end | |
| def forward(n) | |
| @coordinates[0] += n | |
| puts @coordinates, "-----" | |
| end | |
| def backward(n) | |
| @coordinates[0] -= n | |
| puts @coordinates, "-----" | |
| end | |
| def right(n) | |
| @coordinates[1] += n | |
| puts @coordinates, "-----" | |
| end | |
| def left(n) | |
| @coordinates[1] -= n | |
| puts @coordinates, "-----" | |
| end | |
| def fire | |
| @fired_at.push(@coordinates) | |
| puts @coordinates | |
| puts @fired_at, "-----" | |
| end | |
| end | |
| Robot.new.instance_eval do | |
| def do_nothing | |
| forward 1 | |
| backward 1 | |
| end | |
| do_nothing | |
| right 6 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment