Z
Zhenning Guan
topics.each do |f|
times +=1
puts f.title
if times > 4
break
a little ugly, doesn't it?
times +=1
puts f.title
if times > 4
break
a little ugly, doesn't it?
topics.each do |f|
times +=1
puts f.title
if times > 4
break
a little ugly, doesn't it?
topics.each do |f|
times +=1
puts f.title
if times > 4
break
a little ugly, doesn't it?
topics.each do |f|
times +=1
puts f.title
if times > 4
break
Zhenning said:topics.each do |f|
times +=1
puts f.title
if times > 4
break
Zhenning said:topics.each do |f|
times +=1
puts f.title
if times > 4
break
In my opinion, it's nicer than the first version because it doesn't
have
to create a sub array in memory, like all the solutions posted so far
do, which could be a problem with large arrays and large slices.
4.times do |i|
puts topics.title
end
First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin
Slices and 'sub-arrays' aren't copies of the objects, they simply refer to
the identical objects.
In my opinion, it's nicer than the first version because it doesn't have
to create a sub array in memory, like all the solutions posted so far
do, which could be a problem with large arrays and large slices.
First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin
Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
Hi --
Ryan had something like:
topics.first(5).each do |t|
puts t.title
end
which, I believe, does not create an intermediate array because
topics.first(5) returns an enumerator.
Julian said:Slices and 'sub-arrays' aren't copies of the objects, they simply
refer to the identical objects.
Is it your opinion that an array of pointers takes up no memory? Which
takes up more memory: an array of int's or an array of pointers?
First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin
In my opinion, it's nicer than the first version because it doesn't
have
to create a sub array in memory, like all the solutions posted so far
do, which could be a problem with large arrays and large slices.
First doesn't take an argument I'm ruby. It does
If you're using rails enumerable mixin
David showed it in 1.9... but I had to point this out:
% ruby -ve 'puts [1,2,3,4].first(2)'
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
1
2
this goes back to at least 1.7 iirc. #first was introduced in 1.6 and 1.7
gave it an optional length arg.
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.