S
Sam Phoneix
How come this code doesn't return "true" for the following?
x = [1,2,3]
puts(x.include?(Fixnum))
Thanks
x = [1,2,3]
puts(x.include?(Fixnum))
Thanks
How come this code doesn't return "true" for the following?
x = [1,2,3]
puts(x.include?(Fixnum))
Sam said:How come this code doesn't return "true" for the following?
x = [1,2,3]
puts(x.include?(Fixnum))
Thanks
How come this code doesn't return "true" for the following?
x = [1,2,3]
puts(x.include?(Fixnum))
x = [1,2,3]
puts(x.include?(Fixnum))
=> true[1,2,3].map {|number| number.is_a? Fixnum} => [true, true, true]
[1,2,3,"asdfasdfasdf"].map {|number| number.is_a? Fixnum} => [true, true, true, false]
[1,2,3,"asdfasdfasdf"].map {|number| number.is_a? Fixnum}.include?(true)
=> true[1,2,3].include_class?(Fixnum)
Giles said:=> [true, true, true][1,2,3].map {|number| number.is_a? Fixnum}
How come this code doesn't return "true" for the following?
x = [1,2,3]
puts(x.include?(Fixnum))
To get what you want the best approach is map, or one of a few
functions similar to map, such as collect or inject:
Fixnum then this isn't really the best way. Instead I'd use
x.any? {|obj| Fixnum === obj }
which returns a single boolean, and only looks at as many elements of
the array as it needs to.
Yeah, I think that's the best way too.
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.