Hi,
Is there a concise/ruby way to do the following:
[Note: 1 and 2 below are not related.]
(1)
for p in 0...@order.line_items[k].shipment_lines.length
shipline_qty = shipline_qty +
@order.line_items[k].shipment_lines[p].quantity
end
(2)
ts = Array.new
for tk in s.trackings
ts.push(tk)
end
Thanks.
Hi, I''m not an expert so :)
(1)
for p in 0...@order.line_items[k].shipment_lines.length
shipline_qty += @order.line_items[k].shipment_lines[p].quantity
end
(2)
ts = Array.new
s.trackings.each { |tk| ts << tk }
Hope that helps!
2006/1/24, Mufaddal Khumri
<mkhumri@allegromedical.com>:> Hi,
>
> Is there a concise/ruby way to do the following:
> [Note: 1 and 2 below are not related.]
>
> (1)
> for p in 0...@order.line_items[k].shipment_lines.length
> shipline_qty = shipline_qty +
> @order.line_items[k].shipment_lines[p].quantity
> end
>
> (2)
> ts = Array.new
> for tk in s.trackings
> ts.push(tk)
> end
>
>
> Thanks.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Mufaddal Khumri wrote:> Hi, > > Is there a concise/ruby way to do the following: > [Note: 1 and 2 below are not related.] > > (1) > for p in 0...@order.line_items[k].shipment_lines.length > shipline_qty = shipline_qty + > @order.line_items[k].shipment_lines[p].quantity > endshipline_qty = @order.line_items[k].shipment_lines.inject(0){|m, line| m+line.quantity }> (2) > ts = Array.new> for tk in s.trackings> ts.push(tk) > endI don''t get it... What do you want to do with ts that you can''t already do with s.trackings? -- Alex
On 1/24/06, Mufaddal Khumri <mkhumri@allegromedical.com> wrote:> > Hi, > > Is there a concise/ruby way to do the following: > [Note: 1 and 2 below are not related.] > > (1) > for p in 0...@order.line_items[k].shipment_lines.length > shipline_qty = shipline_qty + > @order.line_items[k].shipment_lines[p].quantity > endI''m sure there''s a better way to do this one also but I''m a relative Ruby newb myself... maybe someone else can come up with something; maybe something like: (0...@order.line_items[k].shipment_lines.length).each do |p| shipline_qty +@order.line_items[k].shipment_lines[p].quantity (2)> ts = Array.new > for tk in s.trackings > ts.push(tk) > end > > > Thanks.ts = s.trackings.map { |tk| tk } _______________________________________________> Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060124/9e304ae4/attachment.html