8. Why Procs? Unexpected tAMPER?


#1

https://www.codecademy.com/courses/ruby-beginner-en-L3ZCI/1/3?curriculum_id=5059f8619189a5000201fbcb#

Code should run fine, however, I get the following error on all three proc calls:

(ruby):14: syntax error, unexpected tAMPER
can_ride_1 = group_1.select { &over_4_feet }
                               
(ruby):15: syntax error, unexpected tAMPER
can_ride_2 = group_2.select { &over_4_feet }
                               
(ruby):16: syntax error, unexpected tAMPER
can_ride_3 = group_3.select { &over_4_feet }

Code:

# Here at the amusement park, you have to be four feet tall
# or taller to ride the roller coaster. Let's use .select on
# each group to get only the ones four feet tall or taller.

group_1 = [4.1, 5.5, 3.2, 3.3, 6.1, 3.9, 4.7]
group_2 = [7.0, 3.8, 6.2, 6.1, 4.4, 4.9, 3.0]
group_3 = [5.5, 5.1, 3.9, 4.3, 4.9, 3.2, 3.2]

# Complete this as a new Proc
over_4_feet = Proc.new do |height|
    height >= 4
end

# Change these three so that they use your new over_4_feet Proc
can_ride_1 = group_1.select { &over_4_feet }
can_ride_2 = group_2.select { &over_4_feet }
can_ride_3 = group_3.select { &over_4_feet }

Any and all help appreciated... Thanks.


#2

select(&over_4_feet) would be the correct syntax here. Passing it in a block will result in a syntax error.


#3

My foolishness has shot me in the foot once again! Thank you, Sir.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.