To know the real class of the object


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
3 views
class Klass def class String end def type String end def answer 42 end end k = Klass.new puts k.class puts k.type puts k.answer 

=> String
=> String
=> 42

Actually a question: how can we know the real class of the object?
by | 3 views

1 Answer

0 like 0 dislike
Well, typically, compilers, browsers, etc. read the code from top to bottom.
Accordingly, if the last row will be k puts.answer, where answer is replaced by 42, the class 42.
I think
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
27,858 users