Class: Class

Inherits:
Object show all
Defined in:
lib/glimr/util.rb

Instance Method Summary collapse

Instance Method Details

#wrap_obj_count(*mnames) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/glimr/util.rb', line 113

def wrap_obj_count(*mnames)
  mnames.each{|mn|
    alias_method "__orig__#{mn}", mn
    class_eval <<-EOF
      def #{mn}(*args, &block)
        acount = fcount = hcount = 0
        ObjectSpace.each_object(Array){|o|
          acount -= 1
        }
        ObjectSpace.each_object(Hash){|o|
          hcount -= 1
        }
        ObjectSpace.each_object(Float){|o|
          fcount -= 1
        }
        rv = self.__send__(:__orig__#{mn}, *args, &block)
        ObjectSpace.each_object(Array){|o|
          acount += 1
        }
        ObjectSpace.each_object(Hash){|o|
          hcount += 1
        }
        ObjectSpace.each_object(Float){|o|
          fcount += 1
        }
        puts "After #{self}##{mn}:\n"+
              "      Arrays:  "+(acount-1).to_s+"\n"+ # *args == +1
              "      Hashes:  "+hcount.to_s+"\n"+
              "      Floats:  "+fcount.to_s+"\n"+
              "\n"
        rv
      end
    EOF
  }
end