0
0
Rubyprogramming~20 mins

Everything is an object mental model in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Object Mastery
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 42.class
puts "hello".class
puts :symbol.class
A
Integer
String
Symbol
B
Fixnum
String
String
C
Integer
String
String
D
Fixnum
String
Symbol
Attempts:
2 left
💡 Hint
Remember in modern Ruby versions, Fixnum and Bignum are unified into Integer.
🧠 Conceptual
intermediate
1:30remaining
Which statement best describes Ruby's object model?
Choose the statement that correctly explains Ruby's 'everything is an object' model.
AAll values, including numbers, strings, and even classes themselves, are objects.
BOnly user-defined data types are objects; primitives like numbers are not.
COnly strings and arrays are objects; numbers are treated as primitive values.
DObjects exist only when explicitly created with 'new'; literals are not objects.
Attempts:
2 left
💡 Hint
Think about how you can call methods on numbers and strings in Ruby.
🔧 Debug
advanced
2:00remaining
Why does this Ruby code raise an error?
Look at this Ruby code. Why does it raise a NoMethodError?
Ruby
5.upcase
ABecause 'upcase' requires an argument which is missing here.
BBecause 'upcase' is a private method and cannot be called directly.
CBecause numbers cannot be objects in Ruby.
DBecause 5 is an Integer and Integer does not have an 'upcase' method.
Attempts:
2 left
💡 Hint
Check which methods are available for Integer objects.
Predict Output
advanced
2:00remaining
What is the output of this Ruby code involving classes as objects?
What will this Ruby code print?
Ruby
puts Class.class
puts Integer.class
puts 10.class.class
A
Class
Object
Class
B
Class
Integer
Integer
C
Class
Class
Class
D
Class
Class
Integer
Attempts:
2 left
💡 Hint
Remember that classes themselves are instances of Class.
Predict Output
expert
2:30remaining
What is the output of this Ruby code using singleton methods?
Examine this Ruby code and determine what it prints.
Ruby
obj = "42"
 def obj.description
   "The number is #{self}"
 end
puts obj.description
puts 42.respond_to?(:description)
A
NoMethodError
false
B
The number is 42
false
C
The number is 42
true
D
NoMethodError
true
Attempts:
2 left
💡 Hint
Think about whether the singleton method is defined on the string "42" or on the variable obj.