0
0
Rubyprogramming~10 mins

Pipeline operator concept 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 use the pipeline operator to convert a string to uppercase.

Ruby
result = "hello" [1] String.upcase
Drag options to blanks, or click blank then click option'
A->
B::
C|>
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '->' which is for lambdas, not pipelines.
Using '::' which is for constants or modules.
Using '=>' which is for hashes.
2fill in blank
medium

Complete the code to chain two methods using the pipeline operator.

Ruby
result = "  ruby  " [1] String.strip [2] String.upcase
Drag options to blanks, or click blank then click option'
A->
B|>
C::
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Using different operators for chaining.
Forgetting to repeat the operator between methods.
3fill in blank
hard

Fix the error in the pipeline usage to correctly reverse and then capitalize a string.

Ruby
result = "hello" [1] String.reverse [2] String.capitalize
Drag options to blanks, or click blank then click option'
A|>
B||
C&&
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using logical operators like '||' or '&&' which do not chain methods.
Using '->' which is for lambdas.
4fill in blank
hard

Fill both blanks to create a pipeline that doubles a number and then converts it to a string.

Ruby
result = 5 [1] 2.method(:*) [2] String
Drag options to blanks, or click blank then click option'
A|>
B*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using arithmetic operators instead of pipeline operators between methods.
Mixing different operators for chaining.
5fill in blank
hard

Fill all three blanks to create a pipeline that trims spaces, reverses, and then converts to uppercase.

Ruby
result = "  ruby " [1] String.strip [2] String.reverse [3] String.upcase
Drag options to blanks, or click blank then click option'
A|>
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using different operators in the chain.
Using lambda arrow '->' instead of pipeline operator.