You always need to initialize variables in Ruby.
But you can initialize hashes as following:
# Using {} to creates an empty hash
months = {}
# or create a new empty hash object from Hash class
months = Hash.new
# instead of
months = {"Feb"=>["day1", "day2"]}
To initialize a Array within a Hash:
# Array.new creates a new Array with size 5
# And values within Hash.new block are the default values for the hash
# i.e. When you call the Hash#[], it creates a new array of size 5
months = Hash.new { |hash, key| hash[key] = Array.new(5) }
puts months #=> {}
puts months["Feb"] # Here the Hash creates a new Array inside "Feb" key
puts months #=> {"Feb" => [nil, nil, nil, nil, nil]}
puts months["Feb"][3] = "Day3"
puts months #=> {"Feb" => [nil, nil, nil, "Day3", nil]}
To do the same using an undefined array size:
months = Hash.new { |hash, key| hash[key] = [] }
puts months #=> {}
months["Feb"].push "Day0"
puts months #=> {"Feb" => ["Day0"]}
months["Feb"].push "Day1"
puts months #=> {"Feb" => ["Day0", "Day1"]}
I think a more elegant approach is to use the map method to build your array of days before bind it to "Feb" key:
months = {"Feb" => (0..4).map{ |i| "day#{i}" }}
# => {"Feb"=>["day0", "day1", "day2", "day3", "day4"]}
If you don't want to type the month name you can require the Date class and get the month name passing an Fixnum:
require 'date'
months = {Date::ABBR_MONTHNAMES[2] => (0..4).map{ |i| "day#{i}"}}
# => {"Feb"=>["day0", "day1", "day2", "day3", "day4"]}
To generate the same structure for all months you can do:
days = (0..4).map{ |d| "day#{d}"}
months = (1..12).map{ |m| {Date::ABBR_MONTHNAMES[m] => days }}
# => {"Jan"=>["day0", "day1", "day2", "day3", "day4"],
# "Feb"=>["day0", "day1", "day2", "day3", "day4"],
# ...
# "Dec"=>["day0", "day1", "day2", "day3", "day4"]}
Some useful documentation: