定義部分で、大文字を使い定義するのと小文字を使い定義するのとでは、
以下のように挙動が違ってくるのですが、
なぜ挙動が変わるのでしょうか。
rb
1tmp = gets.chomp 2 3LE = "12345" 4RI = "67890" 5 6def key_check(key) 7 if LE.index(key) 8 "left" 9 elsif RI.index(key) 10 "right" 11 end 12end 13 14puts key_check(tmp) 15# => 16# 1 17# left 18 19#=> 20# 9 21# right 22
rb
1tmp = gets.chomp 2 3le = "12345" 4ri = "67890" 5 6def key_check(key) 7 if le.index(key) 8 "left" 9 elsif ri.index(key) 10 "right" 11 end 12end 13 14puts key_check(tmp) 15# => 16#test.rb:7:in `key_check': undefined local variable or method `le' for main:Object (NameError)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。