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