chignon chignon - 5 months ago 7
Ruby Question

use of comma is causing syntax error

I am having difficulty with commas in arguments. So, I can't use multiple parameters in any method definition. Basically, I can only call methods with 1 argument. I searched all over google and can't find an answer...

I'm using start command prompt with ruby. IRB 2.3.0 . I also had the problem on C9.

A very simple example:

def car_color (color_1 ="blue", color_2 ="red", size="big")
puts "my #{size} car is #{color_1} and #{color_2}."
end


on terminal/irb:
car_color
gives the desired output -the above string - just fine.

BUT

car_color ("x", "y", "a")


produces:


syntax error, unexpected ',', expecting end-of-input car_color ("x", "y",^ "a")


It really sticks being a beginner!

Answer

You got to remove the space between car_color and argument start.

It should be written like this:

car_color("x", "y", "a")

Comments