Challenge - 5 Problems
Ruby Conventions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of method naming convention in Ruby
What will be the output of this Ruby code that follows the naming convention for predicate methods?
Ruby
def valid? true end puts valid?
Attempts:
2 left
💡 Hint
Predicate methods in Ruby usually end with a question mark and return true or false.
✗ Incorrect
In Ruby, methods ending with '?' are used to indicate they return a boolean value. Here, valid? returns true, so puts valid? prints true.
🧠 Conceptual
intermediate1:30remaining
Why follow Ruby conventions for variable names?
Why is it important to follow Ruby conventions for variable names, such as using snake_case?
Attempts:
2 left
💡 Hint
Think about how other programmers read your code.
✗ Incorrect
Using snake_case for variables is a Ruby convention that helps everyone read and understand the code easily, making collaboration smoother.
🔧 Debug
advanced2:00remaining
Identify the error caused by ignoring Ruby method naming conventions
What error will this Ruby code produce and why?
Ruby
def CalculateSum(a, b) a + b end puts CalculateSum(3, 4)
Attempts:
2 left
💡 Hint
Ruby allows method names with capital letters but it is not a convention.
✗ Incorrect
Ruby allows method names with capital letters, so this code runs and outputs 7. However, it breaks the convention of using snake_case, which can confuse readers.
❓ Predict Output
advanced2:00remaining
Effect of ignoring Ruby constant naming conventions
What will be the output of this Ruby code that ignores constant naming conventions?
Ruby
Pi = 3.14 puts Pi Pi = 3.14159 puts Pi
Attempts:
2 left
💡 Hint
Ruby allows reassignment of constants but warns you.
✗ Incorrect
Ruby lets you reassign constants but gives a warning. The code outputs both values, showing the reassignment worked but is discouraged.
🧠 Conceptual
expert2:30remaining
Why do Ruby developers prefer convention over configuration?
Why is the principle of 'convention over configuration' important in Ruby development?
Attempts:
2 left
💡 Hint
Think about how conventions help avoid repetitive setup.
✗ Incorrect
Ruby's 'convention over configuration' means developers follow standard ways to do things, so they spend less time setting up and more time building features.