Bird
Raised Fist0
Rubyprogramming~20 mins

What is Ruby - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ruby Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is Ruby primarily used for?

Ruby is a popular programming language. What is its main use?

ABuilding web applications and scripting
BDesigning hardware circuits
CCreating operating systems
DEditing videos and images
Attempts:
2 left
💡 Hint

Think about what Ruby is famous for in software development.

❓ Predict Output
intermediate
1:00remaining
What is the output of this Ruby code?

Look at the Ruby code below. What will it print?

Ruby
puts 'Hello, Ruby!'
AHello, Ruby!
Bhello, ruby!
CHELLO, RUBY!
DError: undefined method 'puts'
Attempts:
2 left
💡 Hint

Remember Ruby is case-sensitive and 'puts' prints exactly what is inside the quotes.

❓ Predict Output
advanced
1:30remaining
What is the output of this Ruby method call?

Consider this Ruby code. What will it output?

Ruby
def greet(name = 'friend')
  "Hello, #{name}!"
end

puts greet
puts greet('Alice')
AError: wrong number of arguments
B
Hello, !
Hello, Alice!
C
Hello, friend!
Hello, friend!
D
Hello, friend!
Hello, Alice!
Attempts:
2 left
💡 Hint

Look at the default parameter in the method definition.

🔧 Debug
advanced
1:00remaining
What error does this Ruby code raise?

Look at this Ruby code snippet. What error will it cause?

Ruby
arr = [1, 2, 3]
puts arr[5]
AIndexError
Bnil
CTypeError
DNoMethodError
Attempts:
2 left
💡 Hint

What happens when you access an array index that does not exist in Ruby?

🧠 Conceptual
expert
2:00remaining
Which feature is unique to Ruby compared to many other languages?

Ruby has many features. Which one below is a unique characteristic of Ruby?

ADoes not support object-oriented programming
BUses curly braces for blocks instead of do-end
CEverything is an object, even numbers and classes
DRequires explicit type declarations for variables
Attempts:
2 left
💡 Hint

Think about how Ruby treats data and code elements.

Practice

(1/5)
1. What is Ruby primarily known as?
easy
A. A type of database
B. A programming language
C. A web browser
D. An operating system

Solution

  1. Step 1: Understand Ruby's category

    Ruby is a tool used to write instructions for computers, which means it is a programming language.
  2. Step 2: Eliminate other options

    It is not a database, browser, or operating system, so those options are incorrect.
  3. Final Answer:

    A programming language -> Option B
  4. Quick Check:

    Ruby = programming language [OK]
Hint: Ruby is a language to tell computers what to do [OK]
Common Mistakes:
  • Confusing Ruby with a database
  • Thinking Ruby is software like a browser
  • Mixing Ruby with operating systems
2. Which of the following is the correct way to print "Hello" in Ruby?
easy
A. print("Hello")
B. echo "Hello";
C. console.log("Hello")
D. printf("Hello")

Solution

  1. Step 1: Identify Ruby's print syntax

    Ruby uses the method print() to show text on the screen.
  2. Step 2: Check other options for language mismatch

    echo is from PHP, console.log is JavaScript, printf is C-style but less common in Ruby for simple output.
  3. Final Answer:

    print("Hello") -> Option A
  4. Quick Check:

    Ruby print syntax = print("Hello") [OK]
Hint: Ruby uses print() to show text [OK]
Common Mistakes:
  • Using echo instead of print
  • Using console.log from JavaScript
  • Confusing printf with print
3. What will the following Ruby code output?
puts "Ruby" + " is fun"
medium
A. Ruby is fun
B. Ruby+ is fun
C. nuf si ybuR
D. Error

Solution

  1. Step 1: Understand string concatenation in Ruby

    The + operator joins two strings together without extra characters.
  2. Step 2: Understand puts output

    puts prints the string and adds a new line automatically, but the output shown is the text without showing the newline character.
  3. Final Answer:

    Ruby is fun -> Option A
  4. Quick Check:

    "Ruby" + " is fun" = "Ruby is fun" [OK]
Hint: Plus (+) joins strings in Ruby [OK]
Common Mistakes:
  • Thinking + adds a plus sign
  • Confusing puts with print
  • Expecting an error from string addition
4. Find the error in this Ruby code:
puts "Hello World
medium
A. No error, code is correct
B. Missing parentheses after puts
C. puts should be capitalized
D. Missing closing double quote

Solution

  1. Step 1: Check string syntax

    The string starts with a double quote but does not have a closing double quote.
  2. Step 2: Verify other syntax parts

    Parentheses are optional in Ruby for puts, and puts is lowercase by convention, so no error there.
  3. Final Answer:

    Missing closing double quote -> Option D
  4. Quick Check:

    Unclosed string causes syntax error [OK]
Hint: Always close your quotes in strings [OK]
Common Mistakes:
  • Forgetting to close quotes
  • Thinking parentheses are mandatory
  • Capitalizing puts incorrectly
5. You want to create a simple Ruby program that prints each word from an array on a new line. Which code correctly does this?
hard
A. words = ("Ruby", "is", "fun") for word in words puts word end
B. words = ["Ruby", "is", "fun"] print words.join("\n")
C. words = ["Ruby", "is", "fun"] words.each { |word| puts word }
D. words = {"Ruby", "is", "fun"} words.each do |word| print word end

Solution

  1. Step 1: Identify correct array syntax

    words = ["Ruby", "is", "fun"] words.each { |word| puts word } uses square brackets [] to create an array, which is correct in Ruby.
  2. Step 2: Check iteration and printing method

    words = ["Ruby", "is", "fun"] words.each { |word| puts word } uses each with a block and puts to print each word on a new line, which is the correct approach.
  3. Final Answer:

    words = ["Ruby", "is", "fun"]\nwords.each { |word| puts word } -> Option C
  4. Quick Check:

    Array + each + puts = print words line by line [OK]
Hint: Use array.each with puts to print each item [OK]
Common Mistakes:
  • Using parentheses instead of brackets for arrays
  • Using print instead of puts for new lines
  • Using curly braces for arrays
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard