[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

method proposition

Dirk Meijer

1/21/2006 6:58:00 PM

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..
greetings, Dirk.
12 Answers

dblack

1/21/2006 7:07:00 PM

0

Dirk Meijer

1/21/2006 7:17:00 PM

0

hi,


> You don't like "not"? :-)

hmm.. guess i missed that ;-)


> What would switch! do?

switch! would change self

greetings, Dirk.

Dirk Meijer

1/21/2006 7:20:00 PM

0

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

Joe Van Dyk

1/21/2006 7:21:00 PM

0

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?

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


dblack

1/21/2006 7:22:00 PM

0

Joe Van Dyk

1/21/2006 7:26:00 PM

0

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

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?

(I wouldn't want to maintain your programs :-)


Dirk Meijer

1/21/2006 7:31:00 PM

0

> 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

ES

1/21/2006 7:43:00 PM

0

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

I think here is where a Symbol would be most fitting ;)

light_switch = :off
light_switch = :on if dark?


E


Paul Robinson

1/21/2006 7:51:00 PM

0

On 21 Jan 2006, at 19:42, Eero Saynatkari wrote:

> I think here is where a Symbol would be most fitting ;)
>
> light_switch = :off
> light_switch = :on if dark?

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?

--
Paul Robinson


Simon Kröger

1/21/2006 8:14:00 PM

0

Eero Saynatkari wrote:
> 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
>
>
> I think here is where a Symbol would be most fitting ;)
>
> light_switch = :off
> 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