[Ruby] See the essence of ArgumentError

ArgumentError Argument means "argument". ArgumentError will be the message "The number of arguments does not match". Various cases are possible, so Let's consider the essential basic part as an example.


Introduced on the wiki as "a shell for running Ruby interactively (REPL)" I will use irb.

Execute code using the following actual and formal arguments with irb

def test(number)
  puts number * number
end

test(5)

Image from Gyazo If you set (5) to the argument of test and pass a value to the formal argument (number), The result of 25 was output.


Now let's run test with no actual arguments. Image from Gyazo

Then an error occurred. Image from Gyazo

Here is the translation of the error message: Image from Gyazo The computer says "I expected it to have one argument, but it was 0." I'm missing one argument.


Now, let's execute it with two actual arguments. Image from Gyazo

Another error. Image from Gyazo

This time you say "I expected it to have one argument, but it was two." I'm angry that there is one more.

Even if you try to send two actual arguments (5, 6), it will not work if the number of formal arguments (number) on the receiving side is one.

Summary

ArgumentError is an error saying "The number of arguments does not match". Let's check the actual and formal arguments where the method is defined!

Recommended Posts

[Ruby] See the essence of ArgumentError
About the behavior of ruby Hash # ==
[Ruby] Display the contents of variables
part of the syntax of ruby ​​on rails
[Ruby] Cut off the contents of twitter-ads
Ruby from the perspective of other languages
Basics of Ruby
How to find the cause of the Ruby error
[Ruby] Summary of class definitions. Master the basics.
[Ruby on Rails] Until the introduction of RSpec
[Delete the first letter of the character string] Ruby
The story of introducing Ajax communication to ruby
Manage the version of Ruby itself with rbenv
[Ruby] Code to display the day of the week
I checked the number of taxis with Ruby
Count the number of occurrences of a string in Ruby
The essence of AspectJ's mood-why your `@Transactional` is ignored
When the hover of Eclipse is hard to see
[Ruby] The role of subscripts in learning elements in arrays
[Ruby] How to find the sum of each digit
Judgment of the calendar
The world of clara-rules (4)
The world of clara-rules (1)
The world of clara-rules (3)
definition of ruby method
The world of clara-rules (5)
The idea of quicksort
Ruby, Nokogiri: Get the element name of the selected node
[Technical memo] About the advantages and disadvantages of Ruby
[Ruby] Class nesting, inheritance, and the basics of self
Get the URL of the HTTP redirect destination in Ruby
About the [ruby] operator
Try using the query attribute of Ruby on Rails
The idea of jQuery
Review the basic knowledge of ruby that is often forgotten
Determine that the value is a multiple of 〇 in Ruby
[Ruby] Questions and verification about the number of method arguments
Site where you can see the version relation of spring (?)
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
The nth and n + 1st characters of a Ruby string
[Ruby] Creating code using the concept of classes and instances
[Ruby] Display today's day of the week using Date class
[Ruby] About the difference between 2 dots and 3 dots of range object.
I tried to summarize the basic grammar of Ruby briefly
[Ruby] How to retrieve the contents of a double hash
[Ruby] I want to reverse the order of the hash table
Basic methods of Ruby hashes
About the handling of Null
Docker monitoring-explaining the basics of basics-
Basic methods of Ruby arrays
[Ruby] Various types of each
About the description of Docker-compose.yml
Understand the basics of docker
The play of instantiating java.lang.Void
Explanation of the FizzBuzz problem
The basics of Swift's TableView
Median of the three values
[Ruby] List of basic commands
The illusion of object orientation