Last active
August 29, 2015 14:05
-
-
Save briankung/1253d7bb9fa19140c1a5 to your computer and use it in GitHub Desktop.
Objects!
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
| filename = "test_cases.txt" | |
| instructions = InstructionReader.new(filename) | |
| # Returns the number of instructions, or how many rovers are given directions | |
| instructions.count | |
| #=> 2 | |
| instructions[0].initial_coordinates | |
| #=> [1,2] | |
| instructions[0].initial_direction | |
| #=> "N" | |
| instructions[0].commands | |
| #=> "LMLMLMLMM" | |
| rover = Rover.new(instructions[0]) | |
| rover.initial_coordinates | |
| #=> [1,2] | |
| rover.initial_direction | |
| #=> "N" | |
| rover.final_coordinates | |
| #=> [1,3] | |
| rover.final_direction | |
| #=> "N" | |
| # And the same for the next rover. |
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 Rover | |
| def initialize(instructions) | |
| @instructions = instructions | |
| @commands = @instructions.commands.split('') #=> ['M','L','M','M'] | |
| end | |
| def initial_coordinates | |
| @instructions.initial_coordinates | |
| end | |
| def parse_command | |
| command = @commands.shift #=> 'M' | |
| if command == # Do some shit here... | |
| # Do some more shit here | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment