Forum: Ruby getting error using Time.local

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1607cf8d4f5f88a2e6987007785325b9?d=identicon&s=25 Sridhar Gilkams (sridhar_g)
on 2014-04-24 10:43
I am learning Ruby from a book called "Apress Beginning Ruby from Novice
to Professional 2nd edition" in that they have given an example which
is:

Time.local(year, month, day, hour, min, sec, msec)

When I am trying the above example I am getting the below error. How to
solve this issue? Please help.

irb(main):022:0> Time.local(year, month, day, hour, min, sec, msec)
NameError: undefined local variable or method `year' for main:Object
        from (irb):22
        from D:/Ruby200-x64/bin/irb:12:in `<main>'
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2014-04-24 17:46
You need to define the variable "year" or implement a method called
"year" that will return a value.  Typically you would do

year = 2014
month = 3
...
puts Time.local(year, month, day, hour, min, sec, msec)
This topic is locked and can not be replied to.