From 258b2d4ddcc74df6845317c06d249db8d194e570 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Mon, 14 Jul 2014 21:22:11 +0700 Subject: [PATCH 1/2] refactored game file with methods --- game.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/game.rb b/game.rb index 016edb1..3f4f9a1 100644 --- a/game.rb +++ b/game.rb @@ -1,20 +1,22 @@ require 'yaml' -name = "Zack Siri" -# first_letter_first_name = name.split(' ').first[0] -# last_letter_last_name = name.split(' ').last[0] +def data_loader(file_name) + @data ||= YAML.load(File.open(File.join(File.dirname(__FILE__), file_name))) +end -first_initial, last_initial = name.split(' ').map { |n| n[0] } +def name_initials_for(name) + name.split(' ').map { |n| n[0] } +end -puts first_initial -puts last_initial +def data(file = 'got_names', set) + data_loader(file + '.yaml')[set] +end -got_data = YAML.load(File.open(File.join(File.dirname(__FILE__), 'got_names.yaml'))) - -mens_first_name = got_data[:mens_first_name] -house_name = got_data[:house_name] - -puts "#{mens_first_name[first_initial.downcase.to_sym]} of house #{house_name[last_initial.downcase.to_sym]}" +def name_and_house + first_initial, last_initial = name_initials_for("Zack Siri") + [data('got_names', :mens_first_name)[first_initial.downcase.to_sym], + data('got_names', :house_name)[last_initial.downcase.to_sym]].join(' of house ') +end From 8d06c73e4f04e0e0de5a1cf75f56757b9eb47796 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Mon, 14 Jul 2014 21:29:40 +0700 Subject: [PATCH 2/2] cleaned up game file --- game.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game.rb b/game.rb index 3f4f9a1..1af3526 100644 --- a/game.rb +++ b/game.rb @@ -9,7 +9,7 @@ def name_initials_for(name) name.split(' ').map { |n| n[0] } end -def data(file = 'got_names', set) +def data(file, set) data_loader(file + '.yaml')[set] end