Challenge - 5 Problems
Ruby Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Ruby pipeline code?
Consider the following Ruby code using the pipeline operator
|>. What will be printed?Ruby
result = 5 |> ->(x) { x * 2 } |> ->(x) { x + 3 } puts result
Attempts:
2 left
💡 Hint
Remember the pipeline operator passes the result of the left expression as the argument to the right lambda.
✗ Incorrect
The number 5 is first doubled to 10, then 3 is added to get 13.
❓ Predict Output
intermediate2:00remaining
What does this pipeline expression return?
Given this Ruby code, what is the value of
output?Ruby
output = 'hello' |> ->(s) { s.upcase } |> ->(s) { s.reverse } puts output
Attempts:
2 left
💡 Hint
The string is first converted to uppercase, then reversed.
✗ Incorrect
The string 'hello' becomes 'HELLO' after upcase, then reversed to 'OLLEH'.
🔧 Debug
advanced2:00remaining
Why does this pipeline code raise an error?
Look at this Ruby code using the pipeline operator. Why does it raise an error?
Ruby
value = 10 |> ->(x) { x / 0 } |> ->(x) { x + 1 } puts value
Attempts:
2 left
💡 Hint
Think about what happens when you divide a number by zero in Ruby.
✗ Incorrect
Dividing by zero causes a ZeroDivisionError at runtime.
🧠 Conceptual
advanced2:00remaining
What is the main benefit of using the pipeline operator in Ruby?
Choose the best explanation for why the pipeline operator
|> is useful in Ruby programming.Attempts:
2 left
💡 Hint
Think about how data flows through chained operations.
✗ Incorrect
The pipeline operator improves readability by making data flow explicit and linear.
📝 Syntax
expert3:00remaining
Which option correctly uses the pipeline operator with a method that takes multiple arguments?
Given a method
def add(x, y); x + y; end, which pipeline usage is valid to add 5 and 3?Ruby
def add(x, y) x + y end
Attempts:
2 left
💡 Hint
Remember the pipeline operator passes only one argument to the right side.
✗ Incorrect
Option D correctly uses a lambda to accept the pipeline input and calls add with the fixed second argument 3.