Created
August 6, 2011 17:22
-
-
Save o-eight/1129539 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# encoding: utf-8 | |
#曖昧な名前を一意に定めるんだ | |
def fuzzyname_to_symbol(name) | |
case name | |
when "りんご", "林檎" | |
:apple | |
when "バナナ" | |
:banana | |
when "クッキー", "くっきー" | |
:cookie | |
when "ドリアン" | |
:dorian | |
else | |
:unknown | |
end | |
end | |
#本来のデータはこうじゃないけど | |
fuzzy_name_data = ["りんご", "バナナ", "クッキー", "ドリアン", "バールのようなもの"] | |
#曖昧なデータをこれに結びつけるんだ | |
symbol_list = [:apple, :banana, :cookie, :dorian, :unknown] | |
#ここで作った配列に(実際は、作れてないんだが) | |
symbol_list.each do |sym| | |
eval sym.id2name + " = Array.new" | |
end | |
#データを処理しているときにシンボルに結びつけて戻すことで、各配列に振り分けたいんだ | |
fuzzy_name_data.each do |fuz| | |
record = { | |
:fname => fuz, | |
:property => nil | |
} | |
#ここで入れれるつもりだったけど、すでにもうその配列はオワコン | |
eval (fuzzyname_to_symbol(record[:fname]).id2name + " << record") | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment