Mailinglist Archive: yast-devel (246 mails)

< Previous Next >
Re: [yast-devel] Re: [yast-commit] <web-client> master : use lambdas instead loops
  • From: "Duncan Mac-Vicar Prett" <dmacvicar@xxxxxxx>
  • Date: Tue, 4 Aug 2009 17:09:11 +0200
  • Message-id: <200908041709.11188.dmacvicar@xxxxxxx>
On Tuesday 04 August 2009 10:07:41 Klaus Kaempf wrote:
* Josef Reidinger <jreidinger@xxxxxxx> [Aug 04. 2009 10:00]:
+ region = timezones.find { |reg| reg.name == params[:region] }
+ region = {} unless region

This can be further shortened by writing

region = (timezones.find { |reg| reg.name == params[:region] }) || {}

Where I prefer

region = (timezones.find { |reg| reg.name == params[:region] }) ||
Hash.new

to make it less cryptic ;-)

Heh, I think the || is pretty readable. You can even use the keyword 'or' and
make it more english:
region = (timezones.find { |reg| reg.name == params[:region] }) or {}

I prefer [ ] and { } more than Array.new and Hash.new ;-)

--
Duncan Mac-Vicar P. - Engineering Manager, YaST
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)

--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References