From: Matt Mencel Date: 2012-01-10T03:26:19+09:00 Subject: Class instance variable question Hi, I have this class (below) that takes a deeply nested hash and returns back a new hash without all the nesting. The problem I'm having is that it seems to be that @all_values is not empty if I call it a second time from my program. First time is fine, but the next time I use get_all_values_nested, @all_values still has the results in it from the first time it was used. Any thoughts on what I'm doing wrong? I just want @path and @all_values to be empty each time I use the get_all_values_nested function. Thanks, Matt class Tools @path = [] @all_values = {} def self.get_all_values_nested(nested_hash={}) puts "ALL VALS: #{@all_values}" nested_hash.each_pair do |k,v| @path << k case v when Array, DateTime, FalseClass, Fixnum, NilClass, String, TrueClass then @all_values.merge!({"#{@path.join(".")}" => "#{v}"}) @path.pop when Hash then get_all_values_nested(v) else raise ArgumentError, "Unhandled type #{v.class}" end end @path.pop return @all_values end end