Kinda quiet

P

Patrick Spence

Is it my imagination, or are things getting really quiet in this forum?
It seems that the "movers and shakers" in this forum have moved on to
better digs.
 
P

Phlip

Patrick said:
Is it my imagination, or are things getting really quiet in this forum?
It seems that the "movers and shakers" in this forum have moved on to
better digs.

All the fuss is on various forums discussing individual Ruby projects.

Put another way, one wouldn't want to post here if one of those forums were
on-topic. Also, you might get flamed for posting here if one of those forums
were on-topic.
 
J

Justin Collins

Patrick said:
Is it my imagination, or are things getting really quiet in this forum?
It seems that the "movers and shakers" in this forum have moved on to
better digs.

It's quiet because emails from the mailing list aren't coming through.
I've sent Andreas an email about it.

Now, not to get too high up on my soapbox here, but: if you notice
something like this, please say something. The forums are generally a
more newbie-oriented place, and it does no one any good to have people
who are checking out Ruby feel like their messages are going unanswered.
If we want to maintain Ruby's friendly community (I certainly do:
remember "Matz is nice so we are nice"?), then, regardless of how some
of you might feel about the forums, we should at least let Andreas know
when the link appears to be down.

Okay, off the soapbox now.

-Justin
 
B

Brad Tilley

Say I have an array that contains 144 strings. I want to divide the array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

Thank you,
Brad
 
J

Jan Svitok

Say I have an array that contains 144 strings. I want to divide the array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

Thank you,
Brad

require 'enumerator'

ret = []
array.each_slice(12) {|a| ret << a}
 
X

Xavier Noria

Say I have an array that contains 144 strings. I want to divide the
array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of
doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

If those are the 12 natural consecutive sub-arrays:

require 'enumerator'

array.each_slice(12) do |x|
# ...
end

-- fxn
 
F

Farrel Lifson

Say I have an array that contains 144 strings. I want to divide the array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

Thank you,
Brad

require 'enumerator'
numbers = Array(0..143)
numbers.enum_slice(12).inject([]) do |array,slice|
array << slice
end

Farrel
 
D

dblack

Hi --

Say I have an array that contains 144 strings. I want to divide the array
into
12 sub-arrays each containing 12 strings. What is the Ruby Way of doing
this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

Thank you,
Brad

require 'enumerator'

ret = []
array.each_slice(12) {|a| ret << a}

I wish there were a nice way to do this without the temporary array.
One of the first add-on methods I ever wrote for my own use in Ruby
was "in_chunks_of":

[1,2,3,4,5,6].in_chunks_of(2) => [ [1,2], [3,4], [5,6] ]

The ActiveSupport library has something similar (in_groups_of). I
think it would be a handy addition to Array.


David

--
David A. Black | (e-mail address removed)
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
 
P

Pit Capitain

Farrel said:
Say I have an array that contains 144 strings. I want to divide the
array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of
doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

require 'enumerator'
numbers = Array(0..143)
numbers.enum_slice(12).inject([]) do |array,slice|
array << slice
end

require "enumerator"
numbers = Array(0..143)
numbers.enum_slice(12).to_a

Regards,
Pit
 
F

Farrel Lifson

Farrel said:
Say I have an array that contains 144 strings. I want to divide the
array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of
doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

require 'enumerator'
numbers = Array(0..143)
numbers.enum_slice(12).inject([]) do |array,slice|
array << slice
end

require "enumerator"
numbers = Array(0..143)
numbers.enum_slice(12).to_a

Regards,
Pit

That's pretty cool
 
R

Robert Klemme

Say I have an array that contains 144 strings. I want to divide the
array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of
doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

require 'enumerator'

ret = []
array.each_slice(12) {|a| ret << a}

require 'enumerator'

arr = Array.new 144, "x"
ret = arr.to_enum:)each_slice, 12).inject([]) {|a, *x| a << x}

Kind regards

robert
 
P

Pit Capitain

Farrel said:
Farrel said:
Say I have an array that contains 144 strings. I want to divide the
array into
12 sub-arrays each containing 12 strings. What is the Ruby Way of
doing this?
I've looked at slice array[0..11] etc, but that seems a bit clunky.

require 'enumerator'
numbers = Array(0..143)
numbers.enum_slice(12).inject([]) do |array,slice|
array << slice
end

require "enumerator"
numbers = Array(0..143)
numbers.enum_slice(12).to_a

That's pretty cool

Farrel, it was you who found the important method Enumerable#enum_slice.
I just added the standard Enumerable#to_a method. Plus, I'm sure Robert
K. is happy to see more and more people adding #inject to their toolbox :)

Regards,
Pit
 
R

Robert Klemme

Farrel, it was you who found the important method Enumerable#enum_slice.
I just added the standard Enumerable#to_a method. Plus, I'm sure Robert
K. is happy to see more and more people adding #inject to their toolbox :)

Definitively!

robert - inject missionary - klemme
;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top