Created
July 9, 2015 14:54
-
-
Save allolex/d6f5df1b5a03e96d49a1 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 Table | |
| attr_reader :num_legs | |
| def initialize(num_legs) | |
| if num_legs > 0 | |
| @num_legs = num_legs | |
| elsif num_legs == 0 | |
| raise "Tables have one or more legs." | |
| else | |
| raise ArgumentError, "The number of legs has to be greater than zero." | |
| end | |
| end | |
| end | |
| legs = -1 | |
| begin | |
| t = Table.new legs | |
| p t | |
| rescue ArgumentError | |
| puts "So sorry!" | |
| rescue | |
| puts "Say what?" | |
| end | |
| puts "All done!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment