diff --git a/README.md b/README.md index 1dcb4d3..2f32802 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,6 @@ an instance of the `PartnerError` class and `puts` out the result of calling At this point, the code in `custom_errors.rb` should look like this: -```ruby class Person attr_accessor :partner, :name diff --git a/lib/custom_errors.rb b/lib/custom_errors.rb index 53431de..3fd32fe 100644 --- a/lib/custom_errors.rb +++ b/lib/custom_errors.rb @@ -7,15 +7,24 @@ def initialize(name) def get_married(person) self.partner = person - person.partner = self + if person.class != Person + begin + raise PartnerError + rescue PartnerError => error + puts error.message + end + else + person.partner = self + end end + class PartnerError < StandardError + def message + "you must give the get_married method an argument of an instance of the person class!" + end + end end beyonce = Person.new("Beyonce") beyonce.get_married("Jay-Z") puts beyonce.name - - - -