Created
March 9, 2010 11:45
-
-
Save mrorii/326505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
$have_title = {'ゼロの使い魔' => [1,2,3], | |
'バカとテストと召還獣' => [1,2,3,4,5], | |
'涼宮ハルヒ' => [1,2,3,4,5,6]} | |
class Ranobe | |
def buy_new_books(new_title) | |
new_title.each do |new_book| | |
title = new_book[0] | |
volume = new_book[1] | |
if $have_title.key?(title) then | |
# 同シリーズ名の作品を持っている(上の例で言えば「ゼロの使い魔」) | |
if $have_title[title].include?(volume) then | |
puts "同じものを買ってきてしまった" | |
else | |
$have_title[title].push | |
end | |
else | |
# 同シリーズ名の作品を持っていない(上の例で言えば「半月」) | |
# title に新規追加 | |
$have_title[title] = [volume] | |
end | |
end | |
end | |
end | |
bought = [['ゼロの使い魔', 4], | |
['半月', 1]] | |
myobj = Ranobe.new | |
myobj.buy_new_books(bought) | |
p $have_title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment