Calling a method


#1

what is the syntax used for writing the parameters when calling a method ?

def method1 (name)
...
end

method1 (ahmed) or method1 " ahmed " ??

def method2 ( array)
... end

method2 (numbers) or method "numbers" ??


#2
def my_method(arg1, arg2, etc)
  # bla bla bla
  puts "#{arg1} #{arg2} #{etc}"
  # bla bla bla
end

my_method 1, 2, 3
my_method(1, 2, 3)

def no_args
  puts "No arguments"
end

def blank()
  puts "Blank"
end

no_args()
no_args
blank
blank()

Output:

1 2 3
1 2 3
No arguments
No arguments
Blank
Blank

It is also okay to place a space between method name and arguments.

def my_method (arg1, arg2, etc)

Now, if you have or not have quotes will depend on the kind of object you are dealing with.

# Assume MyCar is an object of the Car class
# Assume my_array is some array

some_method "My String"
some_method 48
some_method MyCar
some_method my_array