Skip to content

Commit 07c968c

Browse files
committed
Simplify to_s and inspect
1 parent 6b11145 commit 07c968c

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

lib/concurrent/edge/promises.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -580,17 +580,12 @@ def chain_on(executor, *args, &task)
580580
ChainPromise.new_blocked1(self, @DefaultExecutor, executor, args, &task).future
581581
end
582582

583-
# Short string representation.
584-
# @return [String]
583+
# @return [String] Short string representation.
585584
def to_s
586-
"<##{self.class}:0x#{'%x' % (object_id << 1)} #{state.to_sym}>"
585+
format '<#%s:0x%x %s>', self.class, object_id << 1, state
587586
end
588587

589-
# Longer string representation.
590-
# @return [String]
591-
def inspect
592-
"#{to_s[0..-2]} blocks:[#{blocks.map(&:to_s).join(', ')}]>"
593-
end
588+
alias_method :inspect, :to_s
594589

595590
# Resolves the resolvable when receiver is resolved.
596591
#
@@ -1288,12 +1283,10 @@ def touch
12881283
end
12891284

12901285
def to_s
1291-
format '<#%s:0x%x %s>', self.class, object_id << 1, state
1286+
format '<#%s:0x%x>', self.class, object_id << 1
12921287
end
12931288

1294-
def inspect
1295-
to_s
1296-
end
1289+
alias_method :inspect, :to_s
12971290

12981291
def delayed
12991292
nil

spec/concurrent/edge/promises_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def behaves_as_delay(delay, value)
332332
# meaningful to_s and inspect defined for Future and Promise
333333
expect(head.to_s).to match /<#Concurrent::Promises::Future:0x[\da-f]+ pending>/
334334
expect(head.inspect).to(
335-
match(/<#Concurrent::Promises::Future:0x[\da-f]+ pending blocks:\[<#Concurrent::Promises::ThenPromise:0x[\da-f]+ pending>\]>/))
335+
match(/<#Concurrent::Promises::Future:0x[\da-f]+ pending>/))
336336

337337
# evaluates only up to three, four is left unevaluated
338338
expect(three.value!).to eq 3

0 commit comments

Comments
 (0)