Dear list members,
A beginner’s question:
I wrote a simple programme that assembles exams, choosing the questions
from a database according to certain criteria. The programme does what I
want, but I realised there are certain basic things I don’t understand,
e.g.:
My programme has classes analogous to class Song and class SongList in
the pickaxe book (class Question and class QuestionList).
Class QuestionList includes the definition
def length
@questions.length
end
and that, of course, works.
When, instead of that definition, I make class QuestionList a subclass
of Array (QuestionList < Array), asking for the length doesn’t give me
an error, but returns a length of 0. So “length” doesn’t know what to do
with an instance of QuestionList, although the latter class includes
def initialize
@questions = Array.new
end
and is now a subclass of “Array”.
Why not? Thanks for answers,
Jörg
Prof.Dr.med. Jörg Hagmann-Zanolari
Institute of Biochemistry and Genetics
Centre of Biomedicine, University of Basel
Mattenstrasse 28
CH-4058 Basel
Switzerland
Phone +41 (0)61 267 3565