「Ruby」putsとpメソッドで配列の要素を取得する
使用例
#!/usr/bin/ruby # -*- coding: UTF-8 -*- users = ["A001", "B002", "C003", "D004"] puts users[3] p users[2] emps = ["111", "222", "333"] puts emps[2] p emps[1]
実行結果
>ruby test.rb
D004
“C003"
333
“222"
Coding Changes the World
使用例
#!/usr/bin/ruby # -*- coding: UTF-8 -*- users = ["A001", "B002", "C003", "D004"] puts users[3] p users[2] emps = ["111", "222", "333"] puts emps[2] p emps[1]
実行結果
>ruby test.rb
D004
“C003"
333
“222"