Syntax

Ruby Create a Hash Syntax

In Ruby, create a hash: creates key-value pairs — user = { name: "Ada", age: 36 }

Quick Answer

Syntax
user = { name: "Ada", age: 36 }
RubySyntax

Create a Hash

Code example
user = { name: "Ada", age: 36 }

Creates key-value pairs.

Learn More

How to create a hash 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 a Hash Syntax

Use user = { name: "Ada", age: 36 }.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for create a hash?

Use this pattern: user = { name: "Ada", age: 36 }

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