Ruby復習【W:69.2kg】

=begin
学習Ruby
=end

################################################################################
# 行末までコメント

################################################################################
=begin
begin〜endの間はコメント
=end

################################################################################
# pringメソッド
print("Hello World!\n")

################################################################################
# 制御構造 条件判断 if〜then〜else〜end
isResult = false
if isResult then # tnen 省略可能
print("true\n")
else
print("false\n")
end

################################################################################
# 制御構造 繰り返し while〜do〜end
i = 1
while i < 10 do #doは省略可能
print(i)
i = i + 1
end

################################################################################
# 制御構造 繰り返し times{〜}
i = 0
8.times{
print(i)
i = i + 1
}

################################################################################
# メソッド

def PrintHello
print("Hello!!" + "\n")
end

PrintHello()

################################################################################
# 別ファイル読み込み
require "testlib.rb"
HelloWorld()

require "date"
print(Date.today())
print "\n"

################################################################################
# 配列
name = ["a","bb","ccc"] #配列初期化
print name[0] + "\n"
print name.size()
print "\n"

#ループ処理
name.each{|n|
print(n + "\n")
}

################################################################################
# ハッシュテーブル
hash_table = {"normal"=>"+0","small"=>"-1","big"=>"+1"}
print hash_table["normal"]
print "\n"

#ループ処理
hash_table.each{|key,value|
puts key + "/" + value
}

################################################################################
# 正規表現
p /Ruby/ =~ "Ruby"
p /Ruby/ =~ "Diamond"

################################################################################
# 引数
puts ARGV[0]
puts ARGV[1]

################################################################################
# ファイル読み込み
f = open("test.txt")
text = f.read()
print text
f.clone()

#ファイル1行づつ読み込み
f = open("test.txt")
while text = f.gets()
print text
end
f.clone()