0
0
Rubyprogramming~15 mins

Everything is an object mental model in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Everything is an Object in Ruby
📖 Scenario: Imagine you are exploring how Ruby treats everything as an object. This helps you understand how you can call methods on numbers, strings, and even true/false values.
🎯 Goal: You will create variables of different types and call methods on them to see how Ruby treats everything as an object.
📋 What You'll Learn
Create variables of different types: integer, string, and boolean
Create a variable called number with the value 10
Create a variable called greeting with the value "hello"
Create a variable called is_ruby_fun with the value true
Call the method .class on each variable to find out its class
Print the class of each variable
💡 Why This Matters
🌍 Real World
Understanding that everything is an object helps you write flexible and powerful Ruby code, since you can use methods on any value.
💼 Career
Many Ruby jobs require you to understand object-oriented concepts, and knowing that all data types are objects is fundamental.
Progress0 / 4 steps
1
Create variables of different types
Create a variable called number and set it to 10. Create a variable called greeting and set it to "hello". Create a variable called is_ruby_fun and set it to true.
Ruby
Need a hint?

Use = to assign values to variables. Remember to put quotes around strings and use true for boolean.

2
Call the .class method on each variable
Call the method .class on the variable number and store the result in a variable called number_class. Do the same for greeting storing in greeting_class, and for is_ruby_fun storing in is_ruby_fun_class.
Ruby
Need a hint?

Use the dot . to call the class method on each variable.

3
Print the class of each variable
Use puts to print the value of number_class, greeting_class, and is_ruby_fun_class each on its own line.
Ruby
Need a hint?

Use puts to print each class variable on its own line.

4
Observe the output showing everything is an object
Run the program to see the output. It should print the class of each variable showing that numbers, strings, and booleans are all objects in Ruby.
Ruby
Need a hint?

The output shows the class names: Integer, String, and TrueClass.