The function of comma in this context


#1



What is the function of the comma? Why does the code not work if i remove the comma?


95.upto(100) { |num| print num, " " }


#2

method arguments are separated by comma


#3

Hi, thanks for the reply. What do you mean by method arguments?


#4

print is a method
you're giving it two arguments
since there is more than one, they need to be separated
and the separator is comma


#5

This is what I understand from your answer. Print is a method, arguments are what you want to be pass into the method and to be printed out. So in this case the arguments are num(variable) and " "(string) whereby the , is the separator. To clarify further, string by itself is not an argument right? It will only be an argument if it is passed into some method. Also in this case does the variable num contains integer or string? Hope I am making sense. Programming has been tough for me. Your guidance is really appreciated.


#6

What do you mean with string?

arguments are the values supplied to a method when calling a method

Argument means a value being sent to a method (or other callable) as input

Whether num refers to numbers or strings depends on what you're assigning to it, this assigning is being done by 95's upto method which is described here: https://ruby-doc.org/core-2.2.0/Integer.html#method-i-upto


#7

Hey thanks for answering my questions. I feel enlightened now :slight_smile:


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.