0
0
Rubyprogramming~10 mins

Why everything is an object in Ruby - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a string object in Ruby.

Ruby
greeting = [1]
Drag options to blanks, or click blank then click option'
Astring("Hello")
BHello
C'Hello'.to_s
D"Hello"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text.
Using a method that does not exist like string().
2fill in blank
medium

Complete the code to check the class of an object in Ruby.

Ruby
number = 10
puts number.[1]
Drag options to blanks, or click blank then click option'
Aclass
Bkind
Ctype
Dobject_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using type which is not a Ruby method.
Using kind or object_type which do not exist.
3fill in blank
hard

Fix the error in the code to call a method on an integer object.

Ruby
num = 5
puts num.[1]
Drag options to blanks, or click blank then click option'
Ato_s
Blength
Cupcase
Dsplit
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use string methods on numbers.
Using methods that do not exist for integers.
4fill in blank
hard

Fill both blanks to create a hash with symbol keys and access a value.

Ruby
person = { [1]: "Alice", [2]: 30 }
age = person[:age]
puts age
Drag options to blanks, or click blank then click option'
Aname
Bage
C"name"
D"age"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings as keys but accessing with symbols.
Putting quotes around keys when symbols are expected.
5fill in blank
hard

Fill all three blanks to create an array, add an element, and print its length.

Ruby
fruits = [1]
fruits.[2]("banana")
puts fruits.[3]
Drag options to blanks, or click blank then click option'
A[]
Bpush
Clength
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using append which is not a Ruby array method.
Using parentheses instead of square brackets for arrays.