From: Robert Klemme Date: 2006-10-30T18:52:44+09:00 Subject: Re: Define a hash using %q? On 30.10.2006 01:02, David Vallner wrote: > Robert Klemme wrote: >>> Well, if Ruby had clean blocks, the method using #inject might be more >>> efficient - I don't know how expensive the implicit hash construction >>> for method parameters is. Smalltalk muscle memory working there? >> I am not sure what you are at here. Object creation always costs - even >> small hashes. Reason is memory allocation and GC management overhead. >> > > I meant that with clean blocks, to_enum(:each_slice, 2).to_a.inject({}) > { |h, (k, v)| h[k] = v) } might be the fastest variant because you could > use a non-closure lambda (cheaper to construct, cacheable). A > smalltalker nerve twitch might make you want to use inject to optimize > this way - using idempotent lambdas where possible. Ah, thanks for the explanation! Only remark: the block for #inject would rather look like this, wouldn't it? {|h, (k, v)| h[k] = v; h } Kind regards robert