0
0
Rubyprogramming~10 mins

Everything is an object mental model in Ruby - Interactive Code Practice

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

Complete the code to print the class of the number 10.

Ruby
puts 10.[1]
Drag options to blanks, or click blank then click option'
Aclass
Btype
Ckind
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'type' instead of 'class' causes an error.
2fill in blank
medium

Complete the code to call the upcase method on the string 'hello'.

Ruby
puts 'hello'.[1]
Drag options to blanks, or click blank then click option'
Adowncase
Bupcase
Ccapitalize
Dreverse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'capitalize' only changes the first letter.
3fill in blank
hard

Fix the error in the code to check if 5 is an object.

Ruby
puts 5.[1](Object)
Drag options to blanks, or click blank then click option'
Aobject?
Bis_object?
Cis_a?
Dinstance_of?
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'object?' or 'is_object?' are not valid Ruby methods.
4fill in blank
hard

Fill both blanks to create a hash where keys are strings and values are their lengths.

Ruby
lengths = ['cat', 'dog', 'bird'].each_with_object({}) { |word, h| h[[1]] = [2] }
Drag options to blanks, or click blank then click option'
Aword
Bword.length
Cword.size
Dword.count
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.size also works but is not the expected answer here.
5fill in blank
hard

Fill all three blanks to create a hash with uppercase keys and values greater than 3.

Ruby
result = ['apple', 'bat', 'cat', 'dog'].each_with_object({}) { |word, h| if [3]; h[[1]] = [2] end }
Drag options to blanks, or click blank then click option'
Aword.upcase
Bword
Cword.length > 3
Dword.size < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.size < 3 filters the wrong words.