# Nuby: VisualuRuby, menutest.rb example with check boxes in s

**URL:** <https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479>\
**Category:** Ruby\
**Created:** [December 27, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479 "2006-12-27T15:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [December 27, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479/1 "2006-12-27T15:16:37Z")

</div>

I’m back to looking at visualuRuby, have two quick questions about this  
program:  
[http://vruby.sourceforge.net/sample/menutest.rb](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?

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [December 27, 2006, 3:26pm UTC](https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479/2 "2006-12-27T15:26:38Z")

</div>

Jason M. wrote:

> what does ‘= ! @variable’ do anyway? I’ve never seen an example that did  
> that.  
> = does what you think it does. ! is the unary ‘not’ operator. !false ==  
> true and !true == false.

> Second question:  
> How can what I added be turned into a one-liner?  
> @label.caption = @checking.checked? ? “checked” : “unchecked”

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [December 27, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479/3 "2006-12-27T15:30:39Z")

</div>

On 12/27/06, Devin M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [December 27, 2006, 3:34pm UTC](https://www.ruby-forum.com/t/nuby-visualuruby-menutest-rb-example-with-check-boxes-in-s/80479/4 "2006-12-27T15:34:42Z")

</div>

Jason M. wrote:

> 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”
