Syntax

Ruby Create an Array Syntax

In Ruby, create an array: creates an ordered list — nums = [1, 2, 3] nums << 4

Quick Answer

Syntax
nums = [1, 2, 3] nums << 4
RubySyntax

Create an Array

Code example
nums = [1, 2, 3] nums << 4

Creates an ordered list.

Learn More

How to create an array in Ruby

  1. Open your Ruby file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Ruby Create an Array Syntax

Use nums = [1, 2, 3] nums << 4.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for create an array?

Use this pattern: nums = [1, 2, 3] nums << 4

Can I copy this Ruby code example?

Yes. Use Copy code and adapt the example to your program.

Is this Ruby syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify