Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

weak typing - Does ruby 1.9.2 have an is_a? function?

I googled that there is an is_a? function to check whether an object is an integer or not.

But I tried in rails console, and it doesn't work.

I ran the code like the following:

 "1".is_a?
 1.is_a?

Did I miss something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You forgot to include the class you were testing against:

"1".is_a?(Integer) # false
1.is_a?(Integer) # true

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...