Skip to content

Instantly share code, notes, and snippets.

@allolex
Created July 9, 2015 15:04
Show Gist options
  • Select an option

  • Save allolex/5eda9613269bf1ed481e to your computer and use it in GitHub Desktop.

Select an option

Save allolex/5eda9613269bf1ed481e to your computer and use it in GitHub Desktop.
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 => e
puts "You: #{e.message}"
puts "Me: So sorry!"
rescue => e
puts "Say what?"
puts e.backtrace
end
puts "All done!"
end
create_table(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment