Hi Michal, thanks for taking the time.
I am confused by what the code fragment below does exactly. I *think* i
understand what .inject does, but the code below doesn't make sense to
me (or to irb it seems :) ) ; where does r come from? (I tried irb and
ruby debugger cos I thought I was going crazy but the code doesn't work
- i even thought it was a ruby version issue so i tried 1.8.6 AND 1.9.2
as I have come across a few 1.8/1.9 issues).
Can you please explain in words what:
meta_array.inject({}) { |user_meta, v| user_meta[v.first]=v.last ; r }
does? (e.g. take the meta_array two dimensional array and ... iterate
over the user_meta array etc etc). Out of curiosity where are you
getting 'ruby best practice' from (e.g. can you recommend a good
book/site/blog etc?)
many thanks, marios
On 31/01/11 11:28, Michal Fojtik wrote:
On 28/01/11 20:15 +0200, [email protected] wrote:
Code looks good, applied cleanly, Cucumber is happy, ACK.
A small, minor inline comment bellow.
-- Michal
From: marios <[email protected]>
> max.to_i.times do |i| could be used here as well (but do the same job ;-)
+ key = params[:"meta_name#{i}"]
+ key = "HTTP_X_Deltacloud_Blobmeta_#{key}"
+ value = params[:"meta_value#{i}"]
+ user_meta[key] = value
+ end #max.each do
+ else #can try to get blob_metadata from http headers
+ meta_array = request.env.select{|k,v|
k.match(/^HTTP[-_]X[-_]Deltacloud[-_]Blobmeta[-_]/i)}
+ meta_array.each do |k,v|
+ user_meta[k] = v
+ end
meta_array.inject({}) { |user_meta, v| user_meta[v.first]=v.last ; r }
(same as above ;-) But it's a good Ruby practive to use inject if it's
possible.