Created
March 9, 2010 11:50
-
-
Save mrorii/326515 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 = {'Bob' => [1,2,3], | |
'Michael' => [1,2,3,4,5], | |
'Tom' => [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(volume) | |
end | |
else | |
# 同シリーズ名の作品を持っていない(上の例で言えば「半月」) | |
# $have_title に新規追加 | |
$have_title[title] = [volume] | |
end | |
end | |
end | |
end | |
bought = [['Bob', 4], | |
['Matt', 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