0
0
Rubyprogramming~15 mins

Why conventions matter in Ruby - See It in Action

Choose your learning style9 modes available
Why conventions matter in Ruby
📖 Scenario: Imagine you and your friends are working together to build a small Ruby program. To make sure everyone understands each other's code easily, you decide to follow some common rules about how to name things and organize your code.
🎯 Goal: You will create a simple Ruby program that follows common Ruby conventions for naming variables and methods. This will help you see why using conventions makes your code easier to read and share.
📋 What You'll Learn
Create a variable named user_name and assign it the string "Alice"
Create a method named greet_user that takes one parameter called name
Inside the method, return a greeting string using the parameter name
Call the method greet_user with the variable user_name and print the result
💡 Why This Matters
🌍 Real World
In real projects, following Ruby conventions helps teams read and maintain code easily, avoiding confusion.
💼 Career
Many Ruby jobs expect you to write clean, convention-following code so others can understand and build on your work.
Progress0 / 4 steps
1
Create a variable with a proper Ruby name
Create a variable called user_name and set it to the string "Alice"
Ruby
Need a hint?

Use lowercase letters and underscores for variable names in Ruby.

2
Define a method with a clear name and parameter
Define a method called greet_user that takes one parameter named name
Ruby
Need a hint?

Use def to start a method and end to finish it.

3
Add a return greeting string inside the method
Inside the method greet_user, return the string "Hello, #{name}!" using string interpolation
Ruby
Need a hint?

Use double quotes and #{} to insert the variable inside the string.

4
Call the method and print the greeting
Call the method greet_user with the variable user_name and print the result using puts
Ruby
Need a hint?

Use puts to display the greeting on the screen.