0
也許我一直在盯着我的Ruby書籍,以至於語言不再有任何意義,但我想我也許會問。從ruby方法保存和調用多個變量
我在做的是,而不是通過我的函數頭傳遞大量的變量,或者而不是使用全局變量,我正在尋找保存我的變量在一個方法,並呼籲他們在多個次,貫穿我的職責。我現實中有一個問題,是範圍。
def DateGrab()
print "\nEnter the date you're looking for (Month/Day): "
longdate = gets.strip.split(/\/| /)
if longdate[0].length > 3
month = longdate[0].slice(0..2)
else
month = longdate[0]
end
day = longdate[1]
year = `date | awk '{print $6}'`.strip
grepdate = "#{day}/#{month}/#{year}"
date = Date.parse("#{day}-#{month}-#{year}").strftime('%m%d%Y').strip
end
我期待通過「grepdate」和「日期」,通過多種功能,我覺得利用的方法會更容易些,但每次我嘗試調用該變量,我得到一個「未定義局部變量或方法「錯誤。