開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Ruby
『Learning Ruby』(Michael Fitzgerald 著、O'Reilly Media、2007年、ISBN978-0-596-52986-4)の Chapter 6(Arrays)Review Questions 2を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
2.
コード(TextWrangler)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
a1 = [1,2,3,4,5]
a2 = Array(5..10)
a3 = %w(a b c d e)
[a1,a2,a3].each do |a|
puts a.class
i = 0
a.each do |item|
puts "#{i}: #{item}"
i += 1
end
end
入出力結果(Terminal)
$ ./sample.rb Array 0: 1 1: 2 2: 3 3: 4 4: 5 Array 0: 5 1: 6 2: 7 3: 8 4: 9 5: 10 Array 0: a 1: b 2: c 3: d 4: e $
0 コメント:
コメントを投稿