I want to create a hash, that is initialised with the letters 'A'..'Z'
and ""
on the other hand.
abcliste = {}
('A'..'Z').to_a.each { |letter| abcliste[letter] = ""}
print abcliste # => {"A"=>"", "B"=>"", "C"=>"", ... , "Z"=>""}
But, if I use a class, with the same code, I will get an array ["A", "B", "C", "D", "E", ... , "Z"]
:
class Abcliste
def initialize
@abcliste = {}
@abcliste = ('A'..'Z').to_a.each { |letter| @abcliste.store(letter, "") }
print @abcliste # => ["A", "B", "C", "D", "E", ... , "Z"]
end
end
a = Abcliste.new # => ["A", "B", "C", "D", "E", ... , "Z"]
- Why is this so?
- How can I write a class, so that I generates an hash from ('A'..'Z')