Last active
December 4, 2019 03:26
-
-
Save mizucoffee/1208739ae94c4b6b9b1698af34ed466e to your computer and use it in GitHub Desktop.
Rubyの挙動メモ
This file contains hidden or 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
list = [0, 'a', false] | |
p list[0] # 括弧で取得 | |
# ========================== | |
# シンボルリテラルだとシンボルリテラルで、アロー表記だとstringで取得できる | |
hash = { | |
a: 'data-a', | |
"b": 'data-b', | |
"c" => 'data-c', | |
:d => 'data-d' | |
} | |
# シンボルでアクセス | |
p hash[:a] | |
# 文字列だとnilになる | |
p hash['a'] | |
# シンボルでアクセス | |
p hash[:b] | |
# 文字列だとnilになる | |
p hash['b'] | |
# 文字列でアクセス | |
p hash['c'] | |
# シンボルだとnilになる | |
p hash[:c] | |
# シンボルでアクセス | |
p hash[:d] | |
# 文字列だとnilになる | |
p hash['d'] | |
# これは関数呼び出しになるので不可 | |
# p hash.a | |
# ========================== | |
def func | |
p 'func' | |
end | |
# 括弧は省略可 | |
func | |
# 付けても問題なし | |
func() | |
# ========================== | |
def func2(param1, param2) | |
p 'func2' | |
end | |
# カンマで区切れば括弧は不要 | |
func2 1, 2 | |
# よくある表記も可 | |
func2(1, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment