chignon chignon - 1 year ago 31
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}."

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


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


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

It really sticks being a beginner!

Answer Source

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

It should be written like this:

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