누군가이 2D 배열의 요소를 대체 할 수있는 방법을 말해 줄 수 있습니까? 나는 각각을 시험해 보았고, 포함하고 교체했고, 내가 어디로 잘못 가고 있는지 알 수 없었다. 사전에 도움을 주셔서 감사합니다.Ruby : 다차원 배열에서 일치하는 요소 바꾸기?
class Lotto
def initialize
@lotto_slip = Array.new(5) {Array(6.times.map{rand(1..60)})}
end
def current_pick
@number = rand(1..60).to_s
puts "The number is #{@number}."
end
def has_number
#prints out initial slip
@lotto_slip.each {|x| p x}
#Prints slip with an "X" replacing number if is on slip
#Ex: @number equals 4th number on slip --> 1, 2, 3, X, 5, 6
@lotto_slip.each do |z|
if z.include?(@number)
z = "X"
p @lotto_slip
else
z = z
p @lotto_slip
end
end
end
end
test = Lotto.new
test.current_pick
test.has_number
: 당신은'@lotto_slip = Array.new (5) {Array.new (6) {랜드 (1 쓸 수 .. 60)}}'. –