# Method proposition

**URL:** <https://rubytalk.org/t/method-proposition/24223>\
**Category:** ruby-talk\
**Created:** [21 January 2006 18:58 UTC](https://rubytalk.org/t/method-proposition/24223 "2006-01-21T18:58:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirk\_Meijer](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Dirk\_Meijer](https://rubytalk.org/u/Dirk_Meijer)\
**Post date:** [21 January 2006 18:58 UTC](https://rubytalk.org/t/method-proposition/24223/1 "2006-01-21T18:58:02Z")

</div>

hi all,  
what do you think of these methods:

class TrueClass  
&nbsp;&nbsp;def switch  
&nbsp;&nbsp;&nbsp;&nbsp;false  
&nbsp;&nbsp;end  
end

class FalseClass  
&nbsp;&nbsp;def switch  
&nbsp;&nbsp;&nbsp;&nbsp;true  
&nbsp;&nbsp;end  
end

i think i could find some real use for this, though switch! would probably  
be even more useful..  
greetings, Dirk.

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [21 January 2006 19:06 UTC](https://rubytalk.org/t/method-proposition/24223/2 "2006-01-21T19:06:50Z")

</div>

Hi --

> **···**
>
> On Sun, 22 Jan 2006, Dirk Meijer wrote:
> 
> > hi all,  
> > what do you think of these methods:
> > 
> > class TrueClass  
> > def switch  
> > &nbsp;&nbsp;&nbsp;false  
> > end  
> > end
> > 
> > class FalseClass  
> > def switch  
> > &nbsp;&nbsp;&nbsp;true  
> > end  
> > end
> > 
> > i think i could find some real use for this, though switch! would probably  
> > be even more useful..
> 
> You don't like "not"? 🙂
> 
> What would switch! do?
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net
> 
> "Ruby for Rails", from Manning Publications, coming April 2006!
> 
> > **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
> >
> > NEWER EDITION AVAILABLE
> > 
> > The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> > 
> > 
> > Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![Dirk\_Meijer](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Dirk\_Meijer](https://rubytalk.org/u/Dirk_Meijer)\
**Post date:** [21 January 2006 19:16 UTC](https://rubytalk.org/t/method-proposition/24223/3 "2006-01-21T19:16:38Z")

</div>

hi,

> You don't like "not"? 🙂

hmm.. guess i missed that 😉

> What would switch! do?

switch! would change self

greetings, Dirk.

---

<div class="post-metadata">

**Author:** ![Dirk\_Meijer](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Dirk\_Meijer](https://rubytalk.org/u/Dirk_Meijer)\
**Post date:** [21 January 2006 19:20 UTC](https://rubytalk.org/t/method-proposition/24223/4 "2006-01-21T19:20:19Z")

</div>

hi again,

foobar=true  
foobar=not(foobar)  
doesn't seem to work, while i can see purpose in that,

light\_switch=false  
light\_switch.switch if dark==true

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [21 January 2006 19:21 UTC](https://rubytalk.org/t/method-proposition/24223/5 "2006-01-21T19:21:07Z")

</div>

True would become False. False would become True... Human sacrifice,  
dogs and cats living together - mass hysteria!

> **···**
>
> On 1/21/06, dblack@wobblini.net \<dblack@wobblini.net\> wrote:
> 
> > Hi --
> > 
> > On Sun, 22 Jan 2006, Dirk Meijer wrote:
> > 
> > \> hi all,  
> > \> what do you think of these methods:  
> > \>  
> > \> class TrueClass  
> > \> def switch  
> > \> false  
> > \> end  
> > \> end  
> > \>  
> > \> class FalseClass  
> > \> def switch  
> > \> true  
> > \> end  
> > \> end  
> > \>  
> > \> i think i could find some real use for this, though switch! would probably  
> > \> be even more useful..
> > 
> > You don't like "not"? 🙂
> > 
> > What would switch! do?

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [21 January 2006 19:22 UTC](https://rubytalk.org/t/method-proposition/24223/6 "2006-01-21T19:22:00Z")

</div>

Hi --

> **···**
>
> On Sun, 22 Jan 2006, Dirk Meijer wrote:
> 
> > hi,
> > 
> > > You don't like "not"? 🙂
> > 
> > hmm.. guess i missed that 😉
> > 
> > > What would switch! do?
> > 
> > switch! would change self
> 
> So:
> 
> &nbsp;&nbsp;&nbsp;true.switch!  
> &nbsp;&nbsp;&nbsp;1 == 1 # false
> 
> ?
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net
> 
> "Ruby for Rails", from Manning Publications, coming April 2006!
> 
> > **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
> >
> > NEWER EDITION AVAILABLE
> > 
> > The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> > 
> > 
> > Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![J-Van](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@J-Van](https://rubytalk.org/u/J-Van)\
**Post date:** [21 January 2006 19:26 UTC](https://rubytalk.org/t/method-proposition/24223/7 "2006-01-21T19:26:14Z")

</div>

er, the global value 'true' is the only instance of TrueClass. so,  
doing true.switch! would make true become false?

So then,  
if 1 == 1  
&nbsp;&nbsp;puts "hi"  
end

Wouldn't print anything?

(I wouldn't want to maintain your programs 🙂

> **···**
>
> On 1/21/06, Dirk Meijer \<hawkman.gelooft@gmail.com\> wrote:
> 
> > hi,
> > 
> > \> You don't like "not"? 🙂
> > 
> > hmm.. guess i missed that 😉
> > 
> > \> What would switch! do?
> > 
> > switch! would change self

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [21 January 2006 20:44 UTC](https://rubytalk.org/t/method-proposition/24223/8 "2006-01-21T20:44:35Z")

</div>

Hi --

> **···**
>
> On Sun, 22 Jan 2006, Dirk Meijer wrote:
> 
> > hi again,
> > 
> > foobar=true  
> > foobar=not(foobar)  
> > doesn't seem to work, while i can see purpose in that,
> 
> You would do:
> 
> x = (not x)
> 
> or
> 
> x = !x
> 
> David
> 
> --  
> David A. Black  
> dblack@wobblini.net
> 
> "Ruby for Rails", from Manning Publications, coming April 2006!
> 
> > **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails)**
> >
> > NEWER EDITION AVAILABLE
> > 
> > The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> > 
> > 
> > Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![Dirk\_Meijer](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Dirk\_Meijer](https://rubytalk.org/u/Dirk_Meijer)\
**Post date:** [21 January 2006 19:31 UTC](https://rubytalk.org/t/method-proposition/24223/9 "2006-01-21T19:31:11Z")

</div>

> er, the global value 'true' is the only instance of TrueClass. so,  
> doing true.switch! would make true become false?
> 
> So then,  
> if 1 == 1  
> puts "hi"  
> end
> 
> Wouldn't print anything?

that, on second thought, probably wouldn't work, and the following would  
have to be used:

light\_switch=false  
light\_switch=light\_switch.switch if dark==true

---

<div class="post-metadata">

**Author:** ![Christian\_Neukirche1](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@Christian\_Neukirche1](https://rubytalk.org/u/Christian_Neukirche1)\
**Post date:** [21 January 2006 22:35 UTC](https://rubytalk.org/t/method-proposition/24223/10 "2006-01-21T22:35:36Z")

</div>

dblack@wobblini.net writes:

> You would do:
> 
> x = (not x)

Is it just me, or does the precedence of "not" horribly suck? 😉

> **···**
>
> > David
> 
> --  
> Christian Neukirchen \<chneukirchen@gmail.com\> [http://chneukirchen.org](http://chneukirchen.org)

---

<div class="post-metadata">

**Author:** ![Anonymous\_Coward](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Anonymous\_Coward](https://rubytalk.org/u/Anonymous_Coward)\
**Post date:** [21 January 2006 19:42 UTC](https://rubytalk.org/t/method-proposition/24223/11 "2006-01-21T19:42:43Z")

</div>

I think here is where a Symbol would be most fitting 😉

&nbsp;&nbsp;light\_switch = :off  
&nbsp;&nbsp;light\_switch = :on if dark?  
&nbsp;&nbsp;  
E

> **···**
>
> On 2006.01.22 04:31, Dirk Meijer wrote:
> 
> > \> er, the global value 'true' is the only instance of TrueClass. so,  
> > \> doing true.switch! would make true become false?  
> > \>  
> > \> So then,  
> > \> if 1 == 1  
> > \> puts "hi"  
> > \> end  
> > \>  
> > \> Wouldn't print anything?
> > 
> > that, on second thought, probably wouldn't work, and the following would  
> > have to be used:
> > 
> > light\_switch=false  
> > light\_switch=light\_switch.switch if dark==true

---

<div class="post-metadata">

**Author:** ![Paul\_Robinson1](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Paul\_Robinson1](https://rubytalk.org/u/Paul_Robinson1)\
**Post date:** [21 January 2006 19:50 UTC](https://rubytalk.org/t/method-proposition/24223/12 "2006-01-21T19:50:36Z")

</div>

I'd just like to point out that this now makes it 4 Ruby programmers needed to change a lightbulb (or at least turn it on) so far in this thread. Would anybody like to take a guess at how many it would have taken in other languages?

> **···**
>
> On 21 Jan 2006, at 19:42, Eero Saynatkari wrote:
> 
> > I think here is where a Symbol would be most fitting 😉
> > 
> > &nbsp;&nbsp;light\_switch = :off  
> > &nbsp;&nbsp;light\_switch = :on if dark?
> 
> --  
> Paul Robinson

---

<div class="post-metadata">

**Author:** ![Simon\_Kroger](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Simon\_Kroger](https://rubytalk.org/u/Simon_Kroger)\
**Post date:** [21 January 2006 20:13 UTC](https://rubytalk.org/t/method-proposition/24223/13 "2006-01-21T20:13:49Z")

</div>

Eero Saynatkari wrote:

> > > er, the global value 'true' is the only instance of TrueClass. so,  
> > > doing true.switch! would make true become false?
> > > 
> > > So then,  
> > > if 1 == 1  
> > > puts "hi"  
> > > end
> > > 
> > > Wouldn't print anything?
> > 
> > that, on second thought, probably wouldn't work, and the following would  
> > have to be used:
> > 
> > light\_switch=false  
> > light\_switch=light\_switch.switch if dark==true
> 
> I think here is where a Symbol would be most fitting 😉
> 
> &nbsp;&nbsp;light\_switch = :off  
> &nbsp;&nbsp;light\_switch = :on if dark?

I don't get it...

light\_switch = dark

should be the same as

light\_switch=false  
light\_switch=light\_switch.switch if dark==true

right? (and \*please\* don't compare to 'true' if something is true, it \*is\* already true, comparing it with true doesn't change that - never)

also

light\_switch = !light\_switch

should 'switch' the switch, right?

puzzled, or did i missed the joke?

Simon

> **···**
>
> > On 2006.01.22 04:31, Dirk Meijer wrote:
