From: Timothy Hunter Date: 2006-12-27T23:33:16+09:00 Subject: Re: Nuby: VisualuRuby, menutest.rb example with check boxes in submenus Jason Mayer wrote: > I'm back to looking at visualuRuby, have two quick questions about this > program: > http://vruby.sourceforge.net/sample/menutest.rb > Basically, I don't understand this line: @checking.checked = ! @ > checking.checked? > > I added the following which gives me the desired results. > > if @checking.checked? > @label.caption="checked" > else > @label.caption="unchecked" > end > > First question: > what does '= ! @variable' do anyway? I've never seen an example that did > that. > Second question: > How can what I added be turned into a one-liner? > Read "! @variable" as "not @variable". The value of the expression is either true or false. If @variable is anything other than false or nil, then "! @variable" is false. If @variable is false or nil, then "! @variable" is true. Use the ternary ?: operator to turn your code into a one-liner. Your code is equivalent to @label.caption = @checking.checked? ? "checked" : "unchecked"