Linked Questions

Popular Questions

Creating a method in a class and using it in Ruby

Asked by At

so im trying to write a simple timer program in ruby. I defined my methods in a "Timer" class but when I call them it gives me a NoMethodError. Any ideas why? Thanks for the help.

require "Time"
class Timer

 def start
  $a = Time.now

 end

def stop
Time.now - $a
end

end

puts "Type in 'Start'to to start the timer and then type 'Stop' to stop it"
s = gets.start
st = gets.stop
puts st

Related Questions