0
0
Rubyprogramming~20 mins

Why conventions matter in Ruby - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Conventions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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?
Anil
Bfalse
CSyntaxError
Dtrue
Attempts:
2 left
💡 Hint
Predicate methods in Ruby usually end with a question mark and return true or false.
🧠 Conceptual
intermediate
1:30remaining
Why follow Ruby conventions for variable names?
Why is it important to follow Ruby conventions for variable names, such as using snake_case?
AIt prevents syntax errors in Ruby.
BIt ensures code readability and consistency across Ruby projects.
CIt makes the code run faster.
DIt automatically documents the code.
Attempts:
2 left
💡 Hint
Think about how other programmers read your code.
🔧 Debug
advanced
2: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)
ANo error; outputs 7
BNameError because method names should be snake_case
CSyntaxError due to capital letters in method name
DArgumentError because of wrong method definition
Attempts:
2 left
💡 Hint
Ruby allows method names with capital letters but it is not a convention.
Predict Output
advanced
2: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
ASyntaxError due to reassignment of constant
B3.14\n3.14159
CRuntime warning and outputs 3.14\n3.14159
D3.14\n3.14
Attempts:
2 left
💡 Hint
Ruby allows reassignment of constants but warns you.
🧠 Conceptual
expert
2:30remaining
Why do Ruby developers prefer convention over configuration?
Why is the principle of 'convention over configuration' important in Ruby development?
AIt reduces the number of decisions developers must make, speeding up development.
BIt forces developers to write more configuration files.
CIt makes Ruby code run faster by optimizing configurations.
DIt allows developers to ignore best practices.
Attempts:
2 left
💡 Hint
Think about how conventions help avoid repetitive setup.