class Madlibs::Dictionary

Public Class Methods

new(hash) click to toggle source
# File lib/madlibs/dictionary.rb, line 4
def initialize hash
  # deep clone to prevent side-effects
  @hash = Marshal.load(Marshal.dump(hash))
  @hash_clone = Marshal.load(Marshal.dump(hash))
end

Public Instance Methods

reload() click to toggle source
# File lib/madlibs/dictionary.rb, line 15
def reload
  @hash = Marshal.load(Marshal.dump(@hash_clone))
end
retrieve(type) click to toggle source
# File lib/madlibs/dictionary.rb, line 10
def retrieve type
  return '' if @hash[type].nil? or @hash[type].empty?
  @hash[type].delete @hash[type].sample
end