Push element to existing array in ruby -


i have problem don't know how resolve:

i have code pretty asks user date. problem have can't make array take var limit element whenever user puts new date. array resets whenever method 'new_date' ends.

here code:

def new_date    puts "date please: "   date1 = $stdin.gets.chomp   d, m, y = date1.split('-').map{|x| x.to_i}   limit = day_of_week(d, m, y)   puts days_of_the_week[limit]   $various_dates = []   $various_dates.push(limit) end 

you should not reset array of dates in:

$various_dates = [] 

instead, like:

$various_dates ||= [] 

what does, gets global variable $various_dates, if hasn't been initialized (which means nil), set empty array.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -