At first, I was going to do something like below:
arr = [[1,2],[3,4]]
new_arr =
arr.map do |sub_arr|
sub_arr.map do |x|
x+1
end
end
p new_arr
Conclusion:
[[2,3],[4,5]]
But then I tried to shorten it by “linking” the counters:
arr.map.map{|x| x+1}
Then he gives an error to_ary method missing
I debugged it
arr.each.each{|x| p x}
Conclusion:
[1,2]
[3,4]
which is the original array and only opens once.
How can I link two cards / each counter so that it lists at 2 (or more) levels? Or should he be in a block?
Update:
, -, obj.Enumerator.Enumerator.Enumerator... obj 1 . , , . , (Proc/Lambda, , , , ), . - String#to_proc, , x,y . $0,$1,$2,...
( ):
arr = [[1,2],[3,4]]
new_arr = arr.map(&'[$0+1,$1+1]')
p new_arr
github . , , , :)