任何人都可以帮助一个相对较新的红宝石人,看看为什么我得到这个没有方法错误?将不胜感激!
def comp_block
only_user_valued = @winning_propositions.map { |each_hash| each_hash.select { |key, value| value == @user_sign } }
count_of_each = only_user_valued.map { |count_the_items_in_hash| count_the_items_in_hash.count }
index_array = count_of_each.each_with_index.select { |num, index| num == 2 }.map { |index_spot| index_spot[1] }
if index_array.empty? == true
random_move
else
@nil_valued_values_array = []
@nil_valued_array_true_false = []
index_array.each do |element|
@nil_valued_values_array += [@winning_propositions[element].select { |key, value| value == nil }]
@nil_valued_array_true_false += [@nil_valued_values_array.empty?]
end
nil_value = @nil_valued_values_array.delete({})
move = nil_value[0].keys[0]
if @nil_valued_array_true_false == [false] || @nil_valued_array_true_false == [true, false] || @nil_valued_array_true_false == [false, true]
@possible_places[move] = @comp_sign
#changes the winning prop values in parallel
list_of_matching_arrays=@winning_propositions.select { |key, value| key.to_s.match(move.to_s) }
list_of_matching_arrays.each do |change_hash_value|
change_hash_value[move] = @comp_sign
end
puts @comp_name + " made the move: #{move}"
display_game_board
puts "Here I am defending/BLOCKED!!!!!!"
else @nil_valued_array_true_false == [true] || @nil_valued_array_true_false == [true, true]
random_move
end
end
end