Browse files

Merge remote-tracking branch 'aniero/master'

* aniero/master:
  BenString.in_use? to find out if BenString is in use.

Conflicts:
	lib/ben_string.rb
  • Loading branch information...
2 parents 5d8b5a1 + 244aa8e commit 5f4f96a6eae5257e62dec70a814726bcc3a9a5ff @bleything committed Mar 1, 2011
Showing with 21 additions and 0 deletions.
  1. +10 −0 lib/ben_string.rb
  2. +11 −0 test/test_ben_string.rb
View
10 lib/ben_string.rb
@@ -10,12 +10,22 @@ def version(sep = '.')
return [MAJOR, MINOR, BUGFX].join(sep)
end
end
+
VERSION = ::BenString::Version.version.freeze
end
include Version
# Workaround for Hoe
# VERSION = '1.1.0'
+
+ class << self
+ public
+ def in_use?
+ counts = Hash.new(0)
+ ObjectSpace.each_object { |o| counts[o.class] += 1 }
+ counts[self] > 0
+ end
+ end
public
View
11 test/test_ben_string.rb
@@ -11,4 +11,15 @@ def test_to_ben_s
str = BenString.new
assert_equal str, str.to_ben_s
end
+
+ def test_not_in_use
+ GC.start
+ assert !BenString.in_use?
+ end
+
+ def test_in_use
+ str = BenString.new
+ assert BenString.in_use?
+ end
+
end

0 comments on commit 5f4f96a

Please sign in to comment.