Is there a concise way?


#1

Hi,

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

(1)
for p in removed_email_address@domain.invalid_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.


#2

Hi, I’m not an expert so :slight_smile:

(1)
for p in removed_email_address@domain.invalid_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. removed_email_address@domain.invalid:


#3

On 1/24/06, Mufaddal K. removed_email_address@domain.invalid 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:

(removed_email_address@domain.invalid_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 }


#4

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 removed_email_address@domain.invalid_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?