0
0
Rubyprogramming~10 mins

Method chaining patterns 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 chain methods that convert a string to uppercase.

Ruby
"hello".[1]
Drag options to blanks, or click blank then click option'
Areverse
Bupcase
Cdowncase
Dcapitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'downcase' which makes letters lowercase.
Using 'capitalize' which only changes the first letter.
2fill in blank
medium

Complete the code to chain methods that remove whitespace and then reverse the string.

Ruby
"  ruby  ".[1].reverse
Drag options to blanks, or click blank then click option'
Achomp
Bstrip!
Cstrip
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'strip!' which modifies the string in place and returns nil if no changes.
Using 'chomp' which removes newline characters only.
3fill in blank
hard

Fix the error in the method chain that tries to convert a string to an integer and then add 5.

Ruby
"10".[1] + 5
Drag options to blanks, or click blank then click option'
Ato_s
Bto_sym
Cto_f
Dto_i
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to_s' which keeps it a string and causes an error when adding a number.
Using 'to_sym' which converts to a symbol, not a number.
4fill in blank
hard

Fill both blanks to chain methods that split a sentence into words and then sort them alphabetically.

Ruby
"hello world ruby".[1]([2]).sort
Drag options to blanks, or click blank then click option'
Asplit
B" "
C,
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using ',' as a separator which does not split words correctly.
Using 'join' which combines words instead of splitting.
5fill in blank
hard

Fill all three blanks to chain methods that remove vowels from a string, convert it to uppercase, and then reverse it.

Ruby
"example".[1]([2]).[3].reverse
Drag options to blanks, or click blank then click option'
Adelete
B"aeiou"
Cupcase
Ddowncase
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'downcase' instead of 'upcase' changes case incorrectly.
Not specifying vowels correctly in the delete method.