Type checking of array index value in Ruby -
in javascript if want type checking of array index can this:
var array = [1,2,3,4,"the monster green lagoon"] (i=0; < array.length; i++) { if (typeof(array[i]) === 'number') { console.log("yes these numbers"); } else { console.log("index number " + + " " + array[i] +": no not number"); } }
in ruby don't understand how this. i'm trying type check against integers. understand in ruby world it's considered etiquette use each method basic looping this:
array = [1, 2, 3, 4, 5, 6] array.each { |x| puts x }
the part i'm confused syntax foreign , i'm unclear logic goes. haven't gotten actual type checking yet read compare against integer type thus:
if array[i] == integer
thank you.
a = [1,2,3,4,5] a.all? { |x| x.is_a? integer }
Comments
Post a Comment