Codectionary / Developer documentation / Ruby

Ruby Variables & Strings

Ruby uses local variables without a declaration keyword. Strings can be enclosed in single or double quotes; double-quoted strings support interpolation with #{...}.

About Ruby

Ruby is a dynamic, object-oriented programming language designed to make programming expressive and enjoyable. It is often paired with Ruby on Rails for database-backed websites and applications.

  • Rails web applications
  • Scripting
  • Prototypes
Created by
Yukihiro “Matz” Matsumoto
First released
1995 · first public release
Version / standard
Ruby 4.0

Current stable release line. Check framework compatibility before upgrading.

In the real world

  • GitHub: Its Ruby on Rails web application
  • Shopify: Its commerce platform with Rails
  • 37signals: Basecamp and other Rails products

Facts checked 8 September 2026. Links open the sources; examples describe specific products or documented uses.

Syntax

name = "Ada"
puts "Hello, #{name}"

Examples

A small working example

Follow the values through this example, then change one input.

name = "Ada"
lessons = 3
puts "#{name} completed #{lessons} lessons"

Interpolating a string

A small, runnable example of this syntax.

name = "Ada"
visits = 3
puts "#{name} has #{visits} visits."

Best practices

  • Use meaningful local-variable names and prefer interpolation instead of manually concatenating values into strings.
  • Keep examples small while learning, then combine the idea with a real project.

At a glance

Purpose
Expressive scripting and applications
File extension
.rb
Runs in
Ruby interpreter
Usually used with
Ruby standard library and gems

In plain English

Ruby variable names refer to objects. Assigning a new value can make the same local name refer to a different object.

What you’ll learn

  • Assign a local variable.
  • Read its value.
  • Build a string with interpolation.

Breaking down the syntax

name = value
Assigns a value to a local name.
#{...}
Inserts an expression into a double-quoted string.
puts
Writes a value with a newline.

How it works

Assign

Bind a local name.

Build text

Interpolate values into a string.

Output

Print the message.

When should I use this?

Give meaningful names to values in a script or method.

Common mistakes

A common trap

An uppercase initial letter declares a constant name rather than a local variable.

Incorrect

Name = "Ada" # constant, not a local variable

Corrected

name = "Ada" # local variable

Compare approaches

  • Local variable: Use a lowercase or underscore initial character.
  • Instance variable: Use @name for state belonging to an object.

Explore deeper

Assignment and object mutation differ

Reassigning a local name changes what that name refers to. Mutating a shared object can affect other references to the same object.

Specifications & further reading

Related Ruby documentation