From: Rick DeNatale Date: 2009-12-22T22:39:10+09:00 Subject: Re: newbie: if is not null else... On Tue, Dec 22, 2009 at 8:32 AM, Alfonso Caponi wrote: > Hi forum, > > how can I replace this PHP syntax with Ruby? > > $x = (isset($x) and !empty($x)) ? $x : '-'; > > I would like assign a default value if $x is Null. The approximate Ruby idiom would be $x ||= '-' The only caveat is that this would (re)assign the value if $x were either nil or false. This is usually not an issue, but if so then you could use $x = '-' if $x.nil? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale