[Q] class and case

E

E.-R. Bruecklmeier

Hi,

a = 3

#A
case a
when Fixnum
p "Fixnum"
end

#B
case a.class
when Fixnum
p "Fixnum"
end


why ist #A working while #B isn't?

Thanks!

Eric.
 
A

Austin Ziegler

Hi,

a = 3

#A
case a
when Fixnum
p "Fixnum"
end

#B
case a.class
when Fixnum
p "Fixnum"
end

why ist #A working while #B isn't?

% ri "Module.==="
------------------------------------------------------------- Module#===
mod === obj => true or false
------------------------------------------------------------------------
Case Equality---Returns +true+ if _anObject_ is an instance of
_mod_ or one of _mod_'s descendents. Of limited use for modules,
but can be used in +case+ statements to classify objects by class.

Thus:

case a.class
when Fixnum
p "Fixnum" # => Never Reached
when Class
p "Class!" # => or Object, or Module, or several others, see
a.class.ancestors
end

-austin
 
E

E.-R. Bruecklmeier

Austin Ziegler schrieb:

% ri "Module.==="
------------------------------------------------------------- Module#===
mod === obj => true or false


Thanks a lot!

Eric.
 

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

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top