Class: Increment

Inherits:
Object
  • Object
show all
Defined in:
lib/increment.rb

Overview

file: increment.rb

Class Method Summary collapse

Class Method Details

.update(file = 'counter.txt') ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/increment.rb', line 7

def self.update(file='counter.txt')

  i = '1'
  
  if File.exists? file then
    File.open(file, 'r+'){|f| i = f.read.succ; f.rewind; f.write i}
  else
    File.open(file,'w'){|f| f.write i}
  end
  
  return i
end