True and false logical states are represented with true
and false
in Ruby.
happy = true
sad = false
Ruby allows you to compare objects to each other using the normal equality symbols:
==
to see if two objects are equal>
to see if the object on the left is greater than the object on the right<
to see if the object on the left is less than the object on the right.>=
or <=
to test for "greater than or equal to" and "less than or equal to" respectively.You can also use boolean logic with the normal operators:
&&
or and
to check if x and y
are true||
or or
to check if x or y
is true.!
or not
to invert equality - e.g. x != y
(x does not equal y)Here are some examples:
# Is "true equal to false"?
true == false # false
# Is "true not equal to false"
true != false # true
# Is 5 greater than 4?
5 > 4 # true
# Is 3 less than or equal to 2?
3 <= 2 # false
Continuing your work with the amusement park, you are tasked with writing some utility methods to facilitate checking if an attendee can use a ride.
Implement the Attendee#has_pass?
method to return a boolean (true
/false
) value based on the presence of a ride pass.
Attendee.new(100).has_pass?
# => false
Implement the Attendee#fits_ride?
method to see if an attendee fits a ride based on their height.
The ride's required minimum height is provided as an argument.
An attendee must have height greater than or equal to ride's required minimum height.
Attendee.new(140).fits_ride?(100)
# => true
Implement the Attendee#allowed_to_ride?
method to see if an attendee is allowed to go on a ride. The ride's required minimum height is provided as an argument. An attendee must have a ride pass and be able to fit the ride.
attendee = Attendee.new(100)
attendee.issue_pass!(42)
attendee.allowed_to_ride?(120)
# => false
Sign up to Exercism to learn and master Ruby with 20 concepts, 120 exercises, and real human mentoring, all for free.