Created
July 9, 2015 14:58
-
-
Save allolex/b9274dce057e7e157c5f 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 | |
| def create_table(legs) | |
| begin | |
| t = Table.new legs | |
| p t | |
| rescue ArgumentError | |
| puts "So sorry!" | |
| rescue | |
| puts "Say what?" | |
| end | |
| puts "All done!" | |
| end | |
| create_table(-1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment