class NoteManger

Constants

FILE_NAME

Public Class Methods

new() click to toggle source
# File bin/cvnotes, line 4
def initialize
  @hash = {}
  read
end

Public Instance Methods

add(key, value) click to toggle source
# File bin/cvnotes, line 9
def add(key, value)
  @hash[key] = value
  write
end
delete(key) click to toggle source
# File bin/cvnotes, line 22
def delete(key)
  v = @hash.delete(key)
  write
  v
end
list() click to toggle source
# File bin/cvnotes, line 18
def list
  @hash.map{|k,v| k + '=' + v}.join("\n")
end
show(key) click to toggle source
# File bin/cvnotes, line 14
def show(key)
  @hash[key]
end

Private Instance Methods

read() click to toggle source
# File bin/cvnotes, line 29
def read
  return unless File.exists?(FILE_NAME)
  File.open(FILE_NAME,'r') do |f|
    f.each_line do|line|
      k,v = line.split('=')
      @hash[k] = v
    end
  end
end
write() click to toggle source
# File bin/cvnotes, line 39
def write
  File.open(FILE_NAME,'w') do |f|
    @hash.each do |k,v|
      f.puts "#{k}=#{v}"
    end
  end
end