Skip to content

Instantly share code, notes, and snippets.

@wobh
Last active December 15, 2015 09:49
Show Gist options
  • Save wobh/5241217 to your computer and use it in GitHub Desktop.
Save wobh/5241217 to your computer and use it in GitHub Desktop.
class Robot
attr_reader :name, :instruction_count, :created_at, :reset_at
def make_name(name_length=5)
return Array.new(name_length){rand(36).to_s(36)}.join.upcase
end
def incf_instruction_count
@instruction_count += 1
end
def set_name()
@name = make_name
incf_instruction_count()
end
def name()
incf_instruction_count()
@name
end
def initialize()
@instruction_count = 0
@created_at = Time.now
@reset_at = Time.now
set_name()
end
def reset
set_name()
@reset_at = Time.now
end
def timers
return [@reset_at, @created_at]
end
def elapse_timers
return [Time.now - @reset_at, Time.now - @created_at]
end
def report_timers
reset_time, create_time = elapse_timers
puts "#{reset_time} seconds since reset; #{create_time} seconds since created."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment