On Aug 15, 3:51=A0am, Kevin Nolan <kpno... / insgraph.com> wrote:
>
> =A0 =A0 =A0unless (ar =3D Model.find(...)).nil?
> =A0 =A0 =A0 =A0 val =3D ar.attribute
> =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 val =3D DEFAULT
>
> =A0 =A0or the equivalent expression.
>
> It seems to me that this is very unRuby-like and I don't see any similar
> usages in any of the code-bases in which I have looked.
>
> Will someone please provide a counter-example?

Does the Model.find(...) need to be buried in a test condition?  If
it's retrieving worthwhile data, it's worth a line of its own.

  model =3D Model.find(...)
  val =3D (model && model.attribute) || DEFAULT

The second line could be called idiomatic Ruby.  Whether it appeals to
you or not, I can't predict :)

For situations where more complex processing is required before
setting the variable, I am a _big_ fan of these:

  val =3D
    if condition then
      processing
      processing
      value1
    else
      processing
      value2
    end

  val =3D
    case x
    when 1: ...
    when 2: ...
    ...
    end

Cheers,
Gavin