[Ruby] Questions and verification about the number of method arguments


method1 a b, c

If so, which method argument is c?

In Ruby, you don't have to put commas or parentheses in the method arguments. However, in the case of this system, I think that a problem will occur. So, this time, I actually tried it and verified it. I was wondering about the following questions because there weren't many articles.

Scenes that seem to have problems

For example

method1 a, b


method1(a, b)

It means (I got an error when I tried to define a method with the name method, so I set it as method1.).

method1 a b



It means that. It's good so far (although it's already a little strange at this point ... it's tough for beginners ...)

Question here

method1 a b, c

Isn't there two possibilities?




Both possibilities.

What you should check here is

is. You just need to confirm this. (At this point, it's tough for the reader.) But what about variadic arguments? Perhaps one of them has priority. ..

Now, let's verify which of the above patterns is used.


def a *temp
  p "The number of arguments to a is"
  p temp.size

def method1 *temp
  p "The number of arguments of method1 is"
  p temp.size

Result is,,,

method1 a 1, 2
# "The number of arguments to a is"
# 2
# "The number of arguments of method1 is"
# 1

That is, the above

method1(a(1, 2))

Was received. It seems that the above possibility 2 has been adopted.

Recommended Posts

[Ruby] Questions and verification about the number of method arguments
About call timing and arguments of addToBackStack method
[Technical memo] About the advantages and disadvantages of Ruby
About the behavior of ruby Hash # ==
[Ruby] About the difference between 2 dots and 3 dots of range object.
About the role of the initialize method
Method to add the number of years and get the end of the month
About the operation of next () and nextLine ()
About the number of threads of Completable Future
About the mechanism of the Web and HTTP
About the method
[Ruby basics] About the role of true and break in the while statement
Think about the combination of Servlet and Ajax
[Ruby] Arguments with keywords and default values of arguments
About next () and nextLine () of the Scanner class
I checked the number of taxis with Ruby
Output about the method # 2
About the length method
definition of ruby method
About the authenticate method.
About the map method
About the ancestors method
About the [ruby] operator
About the to_s method.
Count the number of occurrences of a string in Ruby
[Ruby] I thought about the difference between each_with_index and each.with_index
About the difference between classes and instances in Ruby
Verification of the relationship between Docker images and containers
[Ruby] Class nesting, inheritance, and the basics of self
Be careful about Ruby method calls and variable references
Find the greatest common divisor and least common multiple of any number of integers in Ruby
Pass arguments to the method and receive the result of the operation as a return value
About the handling of Null
About truncation by the number of bytes of String on Android
The permission specification of the FileUtils method is an octal number.
Output about the method Part 1
about the where method (rails)
About the description of Docker-compose.yml
Command to check the number and status of Java threads
About the difference between "(double quotation)" and "single quotation" in Ruby
I want to call a method and count the number
A note about the seed function of Ruby on Rails
The nth and n + 1st characters of a Ruby string
About Ruby hashes and symbols
[Ruby] Creating code using the concept of classes and instances
About the same and equivalent
About Ruby and object model
Consideration about the times method
About Ruby classes and instances
[Java] I thought about the merits and uses of "interface"
The first year of new graduates thought about an implementation method that makes use of TDD (ruby)
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
[Ruby] Specify the argument name of the method. Meaning of the colon (:) at the end
Easy to understand the difference between Ruby instance method and class method.
About the basics of Android development
wrong number of arguments (given 1, expected 0)
About fastqc of Biocontainers and Java
[Ruby] present/blank method and postfix if.
About the equals () and hashcode () methods
[Ruby] See the essence of ArgumentError
About Ruby single quotes and double quotes