I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
Enumerators are, in my view, a bit less transparent than most Ruby
constructs, so this may look more cryptic than it's worth. The basic
idea is that you're creating an object -- an Enumerator -- that has no
real data of its own but that represents, so to speak, the possibility
of an enumeration over @array, sliced up into groups of four. Instead
of enumerating, I've converted it to a plain array with the *
operator.
@array.each_with_index do |val, idx| @grid[idx/4][idx%4] = val
end
Blessings,
TwP
···
On 11/14/06, Giant Cranes <ruby-forum@gavinjoyce.com> wrote:
Hi,
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].
On 11/14/06, Giant Cranes <ruby-forum@gavinjoyce.com> wrote:
Hi,
I have been learning ruby for the past week and am completely hooked.
Most of the code I am producing is elegant (ruby's credit), although I
am having trouble elegantly converting a single dimension array with 16
elements into a two-dimension grid [4x4].