V
V
Vyacheslav Tretiak2010-12-22 01:23:32
ruby
Vyacheslav Tretiak, 2010-12-22 01:23:32

Find out the real class of an object

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 the question is: how can you find out the real class of an object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2010-12-22
@butteff

Well, as a rule, compilers, browsers, etc. read the code from top to bottom.
Accordingly, if the last line is puts k.answer, where answer is replaced by 42, then the class will be 42.
I think so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question