is this wrong? ` def ticket_price @age => 60 ? 10 : 15 end` in ruby

The syntax of the code you provided is incorrect. The correct syntax for defining a method in Ruby would be as follows:

main.rb
def ticket_price(age)
  age >= 60 ? 10 : 15
end
48 chars
4 lines

In this corrected code snippet, we define a method called ticket_price that takes an age parameter. The method uses a ternary operator ?: to determine the ticket price based on the age. If the age is greater than or equal to 60, the price will be 10; otherwise, it will be 15.

Remember to always use parentheses when defining method parameters in Ruby, and make sure the expression inside the ternary operator evaluates to a boolean to correctly determine the ticket price.

related categories

gistlibby LogSnag