Forum: Ruby getting error using Time.local

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)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.