0
0
Rubyprogramming~10 mins

Why conventions matter in Ruby - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a greeting message using a conventional Ruby method.

Ruby
def greet
  puts [1]
end
greet
Drag options to blanks, or click blank then click option'
Aprint "Hello, world!"
B"Hello, world!"
Cecho "Hello, world!"
Dconsole.log("Hello, world!")
Attempts:
3 left
💡 Hint
Common Mistakes
Using print without quotes
Using JavaScript syntax like console.log
2fill in blank
medium

Complete the code to define a class with a conventional Ruby naming style.

Ruby
class [1]
  def initialize(name)
    @name = name
  end
end
Drag options to blanks, or click blank then click option'
Aperson
BpersonClass
Cperson_class
DPerson
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or snake_case for class names
3fill in blank
hard

Fix the error in the method name to follow Ruby conventions.

Ruby
def [1](age)
  puts "Age is #{age}"
end
Drag options to blanks, or click blank then click option'
Aget_age
BGetAge
CgetAge
DGETAGE
Attempts:
3 left
💡 Hint
Common Mistakes
Using CamelCase or uppercase for method names
4fill in blank
hard

Fill both blanks to create a hash with symbol keys using Ruby conventions.

Ruby
person = { [1]: "Alice", [2]: 30 }
Drag options to blanks, or click blank then click option'
A:name
Bname
C:age
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings or bare words as keys without colon
5fill in blank
hard

Fill all three blanks to write a conventional Ruby loop that prints numbers 1 to 3.

Ruby
3.times do |[1]|
  puts [2] + [3]
end
Drag options to blanks, or click blank then click option'
Ai
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not adding 1 to start counting at 1