init an array db
get a record , loop on all records indexing by i
while record.start_at <= record.end_at
put in the db array [record.start_at, i]
end while
loop on records
end
but it seems that's Ruby doesn't like it .. what's wrong ? is theer any way to write it better ?
db = []
record.each do |b|
aDate = b.start_at
i = 0
while aDate <= b.end_at
db << [ aDate, i ]
i++
aDate= aDate + i
end
end
On 02/10/06, Josselin <josselin@wanadoo.fr> wrote:
I wrote the following loop some records ,
init an array db
get a record , loop on all records indexing by i
while record.start_at <= record.end_at
put in the db array [record.start_at, i]
end while
loop on records
end
but it seems that's Ruby doesn't like it .. what's wrong ? is theer any
way to write it better ?
db =
record.each do |b|
aDate = b.start_at
i = 0
while aDate <= b.end_at
db << [ aDate, i ]
i++
aDate= aDate + i
end
end
thansk Tom & Steph
newbie I am mixin any languages into it....
I actually need to remember first that Ruby is OO, so i.next makes more sense compared to i++
joss
···
On 2006-10-02 14:54:58 +0200, Stephane Elie <stephane.elie@gmail.com> said:
Hi Josselin,
Tom is right about the "i++".
Also, it doesn't look like your pseudo-code matches your ruby code functionality.
I'll give it a shot as what you may want to do, just a guess...
db =
record.each do |b|
(b.end_at - b.start_at).times { |i| db << [b.start_at+i, i ] }
end
Don't confuse the variable i with the object it contains. The
expression i++ simply asks the object 2 for it's successor leaving it
unchanged.
i += 1
which is the same as:
i = i + 1
computes the value of i + 1 and assigns the result to the variable i.
you could also use
i = i.next
···
On 10/2/06, Josselin <josselin@wanadoo.fr> wrote:
On 2006-10-02 14:54:58 +0200, Stephane Elie <stephane.elie@gmail.com> said:
> Hi Josselin,
>
> Tom is right about the "i++".
>
> Also, it doesn't look like your pseudo-code matches your ruby code
> functionality.
>
> I'll give it a shot as what you may want to do, just a guess...
>
> db =
> record.each do |b|
> (b.end_at - b.start_at).times { |i| db << [b.start_at+i, i ] }
> end
thansk Tom & Steph
newbie I am mixin any languages into it....
I actually need to remember first that Ruby is OO, so i.next makes more
sense compared to i++