On Mon, Jun 14, 2010 at 5:48 PM, Roger Pack <> wrote=
:
> I read this once:
>
> Operator ||=3D can be shorthand for code like:
> =A0x =3D "(some fallback value)" unless respond_to?
or x
>
> How would that look like exactly, in shorthand, any guesses?
I don't know where you read that, but it has no basis in reality. The
semantics of ||=3D have nothing to do with whether or not a method
exists.
The closest translation of
x ||=3D y
(x || x =3D y)
This is close, except that it will blow up if x isn't already defined.
another alternative might be
(defined? x) ? (x || x =3D y) : y
Which avoids the problem when x isn't defined, but isn't exactly what
the 'compiled' ruby code does, whether that 'code' is YARV 'byte
codes' or an AST in MRI pre 1.9
--=20
Rick DeNatale
Blog:
http://talklikeaduck.denhaven2.com/
Github:
http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR:
http://www.workingwithrails.com/pers...-rick-denatale
LinkedIn:
http://www.linkedin.com/in/rickdenatale