Skip to content

Instantly share code, notes, and snippets.

@QuillyT
Last active March 19, 2021 17:16
Show Gist options
  • Save QuillyT/25d9f65c9a82277434531f1da99ba553 to your computer and use it in GitHub Desktop.
Save QuillyT/25d9f65c9a82277434531f1da99ba553 to your computer and use it in GitHub Desktop.
Hashes in Ruby
hsh = {
'a' => 1,
'b' => 2,
'c' => 3
}
hsh = Hash.new
hsh['a'] = 1
hsh['b'] = 2
hsh['c'] = 3
# Symbols
:test_symbol
hsh = Hash.new
hsh[:a] = 1
hsh[:b] = 2
hsh[:c] = 3
hsh
hsh = {
:a => 1,
:b => 2,
:c => 3
}
hsh = {
a: 1,
b: 2,
c: 3
}
CONSTANT_A = 'a'
CONSTANT_B = 'b'
CONSTANT_C = 'c'
CONSTANT_A = :a
CONSTANT_B = :b
CONSTANT_C = :c
hsh1 = {
CONSTANT_A: 1,
CONSTANT_B: 2,
CONSTANT_C: 3
}
hsh2 = {
CONSTANT_A => 1,
CONSTANT_B => 2,
CONSTANT_C => 3
}
module MyModule
@b = 2
@c = 3
def self.a
@b + @c
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment