DEV Community

Ainsley M Galvez
Ainsley M Galvez

Posted on

Exercism #3: Amusement Park Exercise

My code:

class Attendee
  def initialize(height)
      @height = height
     # raise 'The provided height is outside acceptable limits'
  end
  def height
    @height
    # raise 'Implement the Attendee#height method'
  end
  def pass_id

    @pass_id
    # if pass_id = nil
    #   @pass_id = nil
    # else
    # @pass_id = pass_id
    # end

    # raise 'Implement the Attendee#pass_id method'
  end
  def issue_pass!(pass_id)

    @pass_id = pass_id
  end
  def revoke_pass!

    @pass_id = nil

    # raise 'Implement the Attendee#revoke_pass! method'
  end
end
Enter fullscreen mode Exit fullscreen mode

Initializing is a method used to give a class a value off the bat. In the case of the Amusement Park exercise, you are providing a value to the height variable

if pass_id = nil
   @pass_id = nil
else
   @pass_id = pass_id
end
Enter fullscreen mode Exit fullscreen mode

This code initially worked because I was creating a new instance for pass_id, but was breaking the 4th test because it was preventing a value to be given to pass_id, it kept returning nil.

Things to remember:

  1. MAKE SURE TO COMMENT OUT "raise" SO THAT IT WILL TEST PROPERLY

  2. READ ALL OF THE INSTRUCTIONS MORE THAN ONCE AND TAKE NOTES

Top comments (0)