Overview - Type checking with .class and .is_a?
What is it?
Type checking in Ruby means finding out what kind of object you have. The .class method tells you the exact class of an object, like String or Array. The .is_a? method checks if an object belongs to a class or any of its parent classes. These help your program decide what to do based on the object's type.
Why it matters
Without type checking, programs might try to do things that don't make sense, like adding a number to a word. Type checking helps avoid errors by making sure objects are the right kind before using them. It makes programs safer and easier to understand, especially when working with many different objects.
Where it fits
Before learning type checking, you should know what objects and classes are in Ruby. After this, you can learn about duck typing and polymorphism, which are ways Ruby uses types more flexibly.