what is wrong here? " def cheap = @items.map { |itm| itm[:price].select {|prod| prod if prod < 30}}" in ruby

The syntax of the code you provided is incorrect. It seems like you want to assign the result of the map operation to a variable called "cheap" in Ruby. However, the way you are assigning it is incorrect.

Here's the corrected version of your code:

main.rb
cheap = @items.map { |itm| itm[:price].select { |prod| prod if prod < 30 } }
77 chars
2 lines

In Ruby, you use the = operator to assign a value to a variable. In your code, you used the = operator inside the definition block, which is not valid.

Also, make sure that @items is properly defined before using it in the code snippet you provided.

After this correction, the cheap variable will contain an array of prices (products) that are less than 30.

Please note that this assumes the @items variable is an array of hashes, with each hash having a key :price that contains an array of prices.

related categories

gistlibby LogSnag