Skip to content

Commit

Permalink
Improve to_s and inspection on atomic objects
Browse files Browse the repository at this point in the history
  • Loading branch information
pitr-ch committed Feb 1, 2017
1 parent 2a8a589 commit 594e582
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/concurrent/atomic/atomic_boolean.rb
Expand Up @@ -112,5 +112,11 @@ module Concurrent
#
# @!macro atomic_boolean_public_api
class AtomicBoolean < AtomicBooleanImplementation
# @return [String] Short string representation.
def to_s
format '<#%s:0x%x value:%s>', self.class, object_id << 1, value
end

alias_method :inspect, :to_s
end
end
4 changes: 3 additions & 1 deletion lib/concurrent/atomic/atomic_fixnum.rb
Expand Up @@ -131,7 +131,9 @@ module Concurrent
class AtomicFixnum < AtomicFixnumImplementation
# @return [String] Short string representation.
def to_s
format '<#%s:0x%x value:%s>', self.class, object_id << 1, get
format '<#%s:0x%x value:%s>', self.class, object_id << 1, value
end

alias_method :inspect, :to_s
end
end
2 changes: 2 additions & 0 deletions lib/concurrent/atomic/atomic_reference.rb
Expand Up @@ -46,4 +46,6 @@ class Concurrent::AtomicReference
def to_s
format '<#%s:0x%x value:%s>', self.class, object_id << 1, get
end

alias_method :inspect, :to_s
end
2 changes: 2 additions & 0 deletions lib/concurrent/edge/lock_free_stack.rb
Expand Up @@ -118,5 +118,7 @@ def clear_each(&block)
def to_s
format '<#%s:0x%x %s>', self.class, object_id << 1, to_a.to_s
end

alias_method :inspect, :to_s
end
end
8 changes: 8 additions & 0 deletions spec/concurrent/atomic/atomic_boolean_spec.rb
Expand Up @@ -174,5 +174,13 @@ module Concurrent
expect(AtomicBoolean.ancestors).to include(MutexAtomicBoolean)
end
end

describe '#to_s and #inspect' do
it 'includes the value' do
subject = described_class.new(true)
expect(subject.to_s).to include('true')
expect(subject.inspect).to include('true')
end
end
end
end
9 changes: 9 additions & 0 deletions spec/concurrent/atomic/atomic_fixnum_spec.rb
Expand Up @@ -234,5 +234,14 @@ module Concurrent
expect(AtomicFixnum.ancestors).to include(MutexAtomicFixnum)
end
end

describe '#to_s and #inspect' do
it 'includes the value' do
subject = described_class.new(42)
expect(subject.to_s).to include('42')
expect(subject.inspect).to include('42')
end
end

end
end
8 changes: 8 additions & 0 deletions spec/concurrent/atomic/atomic_reference_spec.rb
Expand Up @@ -147,6 +147,14 @@ module Concurrent

describe AtomicReference do
it_should_behave_like :atomic_reference

describe '#to_s and #inspect' do
it 'includes the value' do
subject = described_class.new('kajhsd')
expect(subject.to_s).to include('kajhsd')
expect(subject.inspect).to include('kajhsd')
end
end
end

describe MutexAtomicReference do
Expand Down

0 comments on commit 594e582

Please sign in to comment.