method proposition

D

Dirk Meijer

------=_Part_15069_12541887.1137869867447
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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.

------=_Part_15069_12541887.1137869867447--
 
D

dblack

Hi --

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?


David

--
David A. Black
(e-mail address removed)

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black
 
D

Dirk Meijer

------=_Part_15093_8212576.1137870984883
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

hi,

You don't like "not"? :)

hmm.. guess i missed that ;-)

What would switch! do?

switch! would change self

greetings, Dirk.

------=_Part_15093_8212576.1137870984883--
 
D

Dirk Meijer

------=_Part_15113_13601266.1137871204715
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

hi again,

foobar=3Dtrue
foobar=3Dnot(foobar)
doesn't seem to work, while i can see purpose in that,

light_switch=3Dfalse
light_switch.switch if dark=3D=3Dtrue

------=_Part_15113_13601266.1137871204715--
 
J

Joe Van Dyk

Hi --



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!
 
J

Joe Van Dyk

hi,



hmm.. guess i missed that ;-)



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 =3D=3D 1
puts "hi"
end

Wouldn't print anything?

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

Dirk Meijer

------=_Part_15141_18479074.1137871856133
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
er, the global value 'true' is the only instance of TrueClass. so,
doing true.switch! would make true become false?

So then,
if 1 =3D=3D 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=3Dfalse
light_switch=3Dlight_switch.switch if dark=3D=3Dtrue

------=_Part_15141_18479074.1137871856133--
 
E

Eero Saynatkari

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 = :eek:ff
light_switch = :eek:n if dark?


E
 
P

Paul Robinson

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

light_switch = :eek:ff
light_switch = :eek:n 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?
 
S

Simon Kröger

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

light_switch = :eek:ff
light_switch = :eek:n 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top