[1] pry(main)> ["hello"][0].class
=> String
[2] pry(main)> ["hello"][1].class
=> NilClass
[3] pry(main)> ["hello"].class
=> Array
[4] pry(main)> ["hello", "world"][0].class
=> String
今日初めて知った。
自分が見た例文では文字列表示の条件分岐で使ってた。
他に何に使えるかわからないけど、知識としてストック。
More than 5 years have passed since last update.
[1] pry(main)> ["hello"][0].class
=> String
[2] pry(main)> ["hello"][1].class
=> NilClass
[3] pry(main)> ["hello"].class
=> Array
[4] pry(main)> ["hello", "world"][0].class
=> String
今日初めて知った。
自分が見た例文では文字列表示の条件分岐で使ってた。
他に何に使えるかわからないけど、知識としてストック。
Register as a new user and use Qiita more conveniently