Class: Object

Inherits:
BasicObject
Defined in:
lib/glimr/util.rb

Instance Method Summary collapse

Instance Method Details



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/glimr/util.rb', line 165

def print_obj_count(label="block", &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 = yield
  ObjectSpace.each_object(Array){|o|
    acount += 1
  }
  ObjectSpace.each_object(Hash){|o|
    hcount += 1
  }
  ObjectSpace.each_object(Float){|o|
    fcount += 1
  }
  puts "After #{label}:\n"+
        "      Arrays:  "+acount.to_s+"\n"+
        "      Hashes:  "+hcount.to_s+"\n"+
        "      Floats:  "+fcount.to_s+"\n"+
        "\n"
  rv
end

#silently_fail(exception = StandardError) ⇒ Object Also known as: silently



158
159
160
161
162
# File 'lib/glimr/util.rb', line 158

def silently_fail(exception = StandardError)
  yield
rescue exception => e
  e
end

#touch!Object



154
155
156
# File 'lib/glimr/util.rb', line 154

def touch!
  @mtime = Time.now.to_f
end