K
Krekna Mektek
Hi list, I've got this probably lame questions.
In the Pickaxe book 2nd ed. they talk about the attr_reader and
attr_writer on pages 28 and 29 of the book.
There are these attr_reader (eh, methods?) things, which use symbols
instead of variables, why does Ruby use symbols here, what would be
the problem if one uses the variable names instead? The symbol is
pointing to the variable, but the variable is the handle on the data
(variable value) anyway. Like a symlink pointing to a symlink pointing
to the actual file.
And on page 44 (Containers, Implementing a SongList container)
class SongList
def [](index)
@songs[index]
end
end
Why is there this [] method in the class SongList, when one is able to
use the [] method on the songs array anyway? Is this because of the
church of good design, that one must access or change the @songs array
via accessor methods, instead of changing the array directly?
Krekna
In the Pickaxe book 2nd ed. they talk about the attr_reader and
attr_writer on pages 28 and 29 of the book.
There are these attr_reader (eh, methods?) things, which use symbols
instead of variables, why does Ruby use symbols here, what would be
the problem if one uses the variable names instead? The symbol is
pointing to the variable, but the variable is the handle on the data
(variable value) anyway. Like a symlink pointing to a symlink pointing
to the actual file.
And on page 44 (Containers, Implementing a SongList container)
class SongList
def [](index)
@songs[index]
end
end
Why is there this [] method in the class SongList, when one is able to
use the [] method on the songs array anyway? Is this because of the
church of good design, that one must access or change the @songs array
via accessor methods, instead of changing the array directly?
Krekna