Skip to content

Instantly share code, notes, and snippets.

@allolex
Created July 9, 2015 14:54
Show Gist options
  • Select an option

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

Select an option

Save allolex/d6f5df1b5a03e96d49a1 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
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