Is there no type in Ruby?

I sometimes see the statement "Ruby has no type". Is it true. ~~ It's not a very accurate expression. ~~ Depending on what you say "with / without type", "Ruby has no type" can be misleading.

You should consider the type of the data itself and the type of the data receiver (variables, formal parameters, etc.) separately.

In Ruby

Has no type. There is no grammatical type declaration, and you can reassign a floating-point number to a variable to which you have assigned a string. You can pass any object to the method that takes the argument [^ m]. In other words, there is no type on the data receiving side.

[^ m]: However, TypeError may be issued when the method is executed by passing the actual argument.

On the other hand, there are many types of data even if you look only at the built-in classes. Well, now young may not be right even if it is said that Ruby classes are rich, but in ancient times it counts as string type, integer type, real number type (floating point number), logical type, array type, etc. There were a lot of programming languages ​​that had only moderate types. Even in modern programming languages, the built-in types (classes) are rather rich.

Well, somehow I wrote that the data type of Ruby is a class, but it can be taken a little broader. See "Data Types" in the official reference glossary. Ruby Glossary (Ruby 3.0.0 Reference Manual)

Ruby 3.0.0 also introduced types on the receiving side. However, I don't describe the type in the Ruby program itself.

Recommended Posts

Is there no type in Ruby?
Variable type in ruby
In 2021, there is no topic in Java these days (Poem)
When there is no output to stdout in docker log
[Ruby] Thinking when there is no receiver in front of the method (it looks like)
[Technical memo] What is "include" in Ruby?
gradle's mybatis-generator-plugin says there is no MapperAnnotationPlugin
Class in Ruby
Chart type Ruby
Initial value when there is no form object property in Spring request
Heavy in Ruby! ??
Behavior when wild card (**) is specified in ruby
The ruby version is managed in the .rbenv / version file
The intersection type introduced in Java 10 is amazing (?)
No enclosing instance of type Hoge is accessible.
[Deep Learning from scratch] 2. There is no such thing as NumPy in Java.
Read mp3 tag (ID3v1) in Ruby (no library used)
About eval in Ruby
Data acquisition method memo when there is HashMap in HashMap
Type determination in Java
Output triangle in Ruby
Fast popcount in Ruby
[Ruby] What is true?
What you write in C # is written in Ruby like this
I got an error! * There is no interactive request template
Integer # pow is recommended for iterative squares solving in Ruby
Determine that the value is a multiple of 〇 in Ruby
ABC177 --solving E in Ruby
Implemented XPath 1.0 parser in Ruby
There is after Kotlin conversion
What is a Ruby module?
Read design patterns in Ruby
Is Ruby all objects, true?
Ruby # {} is not variable expansion
Try functional type in Java! ①
Update Ruby in Unicorn environment
Integer unified into Integer in Ruby 2.4
[Ruby] Exception handling in functions
Use ruby variables in javascript.
About regular expressions in Ruby
I checked with Ruby whether there is a Kaprekar number in an integer within a certain range
Throw an exception and catch when there is no handler corresponding to the path in spring
[Ruby] What is `!!` used for?
[Ruby] What is an instance?
Birthday attack calculation in Ruby
Judgment of fractions in Ruby
Find Roman numerals in Ruby
Try using gRPC in Ruby
[Ruby] Find numbers in arrays
Format Timestamp type in Thymeleaf
NCk mod p in Ruby
Chinese Remainder Theorem in Ruby
I tried to write code like a type declaration in Ruby
How to output the value when there is an array in the array
I tried to make Numeron which is not good in Ruby
[Caution summary] Set Ruby time (Time type/Date type/DateTime type) in the column