Is there a concise way?

Hi,

Is there a concise/ruby way to do the following:
[Note: 1 and 2 below are not related.]

(1)
for p in [email protected]_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 :slight_smile:

(1)
for p in [email protected]_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 K. [email protected]:

On 1/24/06, Mufaddal K. [email protected] wrote:

        end

I’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:

([email protected]_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 }

Mufaddal K. wrote:

Hi,

Is there a concise/ruby way to do the following:
[Note: 1 and 2 below are not related.]

(1)
for p in [email protected]_items[k].shipment_lines.length
shipline_qty = shipline_qty +
@order.line_items[k].shipment_lines[p].quantity
end
shipline_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)
end
I don’t get it… What do you want to do with ts that you can’t already
do with s.trackings?