J
Jonathan Leighton
This code:
--------------
class Time
# Rounds a time sensibly.
# Currently just hour is supported (as that's the only one needed)
def round_to(unit = :hour)
unless min == 0
new_hour = hour
new_hour += 1 if min > 30
time = Time.local(year, month, day, new_hour)
end
time
end
def round_to!(*args)
self = round_to *args
end
end
--------------
Throws this error:
Can't change the value of self (SyntaxError)
self = round_to *args
Why doesn't it work? What can I do instead?
Thanks
--------------
class Time
# Rounds a time sensibly.
# Currently just hour is supported (as that's the only one needed)
def round_to(unit = :hour)
unless min == 0
new_hour = hour
new_hour += 1 if min > 30
time = Time.local(year, month, day, new_hour)
end
time
end
def round_to!(*args)
self = round_to *args
end
end
--------------
Throws this error:
Can't change the value of self (SyntaxError)
self = round_to *args
Why doesn't it work? What can I do instead?
Thanks