I’m italian, then sorry in advance for my bad english:
Is there a method to know a type of object?
For example:
Did you try actually running this code? If so, you wouldn’t have had to
post the question:
<heh.rb>
x = 1
y = [1, 2, 3]
z = {1 => “one”, 2 => “two”}
puts x.type # Must print "int"
puts y.type # Must print "array"
puts z.type # Must print “hash”
NOTE: HAD TO FIX THE ABOVE LINES DUE TO TYPO
</heh.rb>
ruby heh.rb
heh.rb:6: warning: Object#type is deprecated; use Object#class
Fixnum
heh.rb:7: warning: Object#type is deprecated; use Object#class
Array
heh.rb:8: warning: Object#type is deprecated; use Object#class
Hash
…so this is telling you that 1) your code worked, but 2) the #type
method has been deprecated and you should use #class instead.