creating a ! method

K

Kurt V. Hindenburg

Hello,
I have this code. It works fine but I would like to use round_to_interval!.
I could not figure out how to code that. Any suggestions?

class Time
def round_to_interval!
# how?
end

def round_to_interval
self - (self.min % 10) * 60
end
end

Regards,
Kurt
 
J

Jamis Buck

Hello,
I have this code. It works fine but I would like to use
round_to_interval!.
I could not figure out how to code that. Any suggestions?

class Time
def round_to_interval!
# how?
end

def round_to_interval
self - (self.min % 10) * 60
end
end

Time objects are immutable (like numbers, symbols, etc.), so you
cannot alter them directly.

- Jamis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top