DEV Community

Ainsley M Galvez
Ainsley M Galvez

Posted on

Exercism #4: Amusement Park Improvements Exercise

class Attendee
  def initialize(height)
    @height = height
  end
  def issue_pass!(pass_id)
    @pass_id = pass_id
  end
  def revoke_pass!
    @pass_id = nil
  end
  # Do not edit above methods, add your own methods below.
  def has_pass?
    if @pass_id != nil
      pass_id = true
    else
      pass_id = false
    end
    # raise 'Please implement the Attendee#haspass? method'
  end
  def fits_ride?(ride_minimum_height)
     if @height < ride_minimum_height
      ride_minimum_height = false
    else
      ride_minimum_height = true
    end

   # raise 'Please implement the Attendee#fits_ride? method'
  end
  def allowed_to_ride?(ride_minimum_height)
    fits_ride?(ride_minimum_height) && has_pass?

    # raise 'Please implement the Attendee#allowed_to_ride? method'
  end
end
Enter fullscreen mode Exit fullscreen mode

The exercise was to improve the Amusement Park system to allow or reject visitors that have a pass or not and have a qualifying height.

Originally, I did allowed_to_ride? as a if else statement to analyze if both fits_ride? and hass_pass? is true, then it will return allowed_to_ride? true.

However, the if statement didn't work and so I saw this as a solution:

fits_ride?(ride_minimum_height) && has_pass?

This works because it already brings a boolean with the end and saves it onto ride_minimum_height.

According to the mentor, doing an if else statement would be redundant because both allowed_to_ride? and fits_ride? save values onto (ride_minimum_height)

Top comments (0)