0
0
Rubyprogramming~20 mins

Why everything is an object in Ruby - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Object Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Ruby code?
Consider this Ruby code snippet. What will it print when run?
Ruby
puts 5.class
puts 'hello'.class
puts nil.class
A
Integer
String
NilClass
B
Fixnum
String
NilClass
C
int
str
nil
D
Number
Text
Null
Attempts:
2 left
💡 Hint
Check the class of each value using the .class method.
🧠 Conceptual
intermediate
1:30remaining
Why is everything an object in Ruby?
Which of the following best explains why everything in Ruby is an object?
ABecause Ruby treats all data types as instances of classes, allowing uniform behavior and method calls.
BBecause Ruby only supports numbers and strings as objects.
CBecause Ruby uses pointers for all variables.
DBecause Ruby does not have classes or objects.
Attempts:
2 left
💡 Hint
Think about how Ruby allows you to call methods on any value.
🔧 Debug
advanced
1:30remaining
What error does this Ruby code raise?
What error will this Ruby code produce when run?
Ruby
5.upcase
AArgumentError
BNoMethodError
CSyntaxError
DTypeError
Attempts:
2 left
💡 Hint
Check if the Integer class has the method 'upcase'.
Predict Output
advanced
2:00remaining
What is the output of this Ruby code involving objects?
What will this Ruby code print?
Ruby
class Animal
  def speak
    'Hello'
  end
end

obj = Animal.new
puts obj.speak
AAnimal
Bspeak
CHello
DNoMethodError
Attempts:
2 left
💡 Hint
Look at the method defined inside the class and what is called on the object.
🧠 Conceptual
expert
2:30remaining
How does Ruby's object model affect method calls on literals?
Why can you call methods like .to_s or .class on literals such as numbers or strings in Ruby?
ABecause only strings and numbers have methods in Ruby.
BBecause literals are special keywords that have built-in methods.
CBecause Ruby converts literals to strings before calling methods.
DBecause literals are objects and Ruby's object model allows methods to be called on any object.
Attempts:
2 left
💡 Hint
Think about what it means for everything to be an object in Ruby.