Skip to content

Ruby Programming

Master Ruby Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.

🎓 50 cards ⏱️ ~25 min Advanced
Study Full Deck →
Share: 𝕏 Twitter LinkedIn WhatsApp

🎯 What You'll Learn

Preview Questions

12 shown

What is a Symbol in Ruby?

Show ▼

A Symbol is a lightweight, immutable identifier prefixed with a colon, e.g. :name. Symbols are stored in memory only once, making them more efficient than strings for keys and identifiers.
Example: :status, :id

How do you create an Array in Ruby?

Show ▼

An Array is an ordered collection created with square brackets or Array.new.
Examples:
nums = [1, 2, 3]
words = %w[hello world]
empty = Array.new(5, 0)

How do you create a Hash in Ruby?

Show ▼

A Hash is a collection of key-value pairs.
Examples:
h = { name: "Alice", age: 30 }
h = Hash.new(0)
Access values with h[:name].

What is a block in Ruby?

Show ▼

A block is an anonymous chunk of code enclosed in do...end or curly braces { } that can be passed to a method.
Example:
[1,2,3].each { |n| puts n }

What is the difference between do...end and curly braces for blocks?

Show ▼

Both define blocks, but curly braces { } have higher precedence than do...end.
Convention: use { } for single-line blocks and do...end for multi-line blocks.

What is a Proc in Ruby?

Show ▼

A Proc is an object that encapsulates a block of code, allowing it to be stored in a variable and called later.
Example:
greet = Proc.new { |name| puts "Hello, #{name}" }
greet.call("Alice")

What is a Lambda in Ruby?

Show ▼

A Lambda is a special type of Proc that enforces the correct number of arguments and returns control to the calling method.
Example:
square = ->(x) { x * x }
square.call(5) # => 25

What are the differences between a Proc and a Lambda?

Show ▼

Key differences:Argument checking: Lambdas raise an error on wrong argument count; Procs assign nil to missing args.Return behavior: return in a Lambda exits the lambda; return in a Proc exits the enclosing method.

How do you define a class in Ruby?

Show ▼

Use the class keyword:
class Dog
  def initialize(name)
    @name = name
  end
  def bark
    "Woof!"
  end
end

What is the initialize method in a Ruby class?

Show ▼

initialize is the constructor method called automatically when you create a new object with ClassName.new. It is used to set up instance variables.
Example: def initialize(name)
  @name = name
end

What are instance variables in Ruby?

Show ▼

Instance variables start with @ and belong to a specific object instance. They persist for the lifetime of the object.
Example: @name = "Ruby"

What are class variables in Ruby?

Show ▼

Class variables start with @@ and are shared among all instances of a class and its subclasses.
Example:
@@count = 0
Use with caution as subclasses share the same variable.

🎓 Start studying Ruby Programming

🎮 Study Modes Available

🔄

Flashcards

Flip to reveal

🧠

Focus Mode

Spaced repetition

Multiple Choice

Test your knowledge

⌨️

Type Answer

Active recall

📚

Learn Mode

Multi-round mastery

🎯

Match Game

Memory challenge

Related Topics in Programming

📖 Learning Resources