Last active
March 19, 2021 17:16
-
-
Save QuillyT/25d9f65c9a82277434531f1da99ba553 to your computer and use it in GitHub Desktop.
Hashes in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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