Skip to content

Commit 1f0ce6d

Browse files
committed
Refactor duping values from superclasses
1 parent 1d6ee90 commit 1f0ce6d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/thor/base.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,16 @@ def from_superclass(method, default=nil)
603603
else
604604
value = superclass.send(method)
605605

606-
if value
607-
if value.is_a?(TrueClass) || value.is_a?(Symbol)
608-
value
609-
else
610-
value.dup
611-
end
606+
# Ruby implements `dup` on Object, but raises a `TypeError`
607+
# if the method is called on immediates. As a result, we
608+
# don't have a good way to check whether dup will succeed
609+
# without calling it and rescuing the TypeError.
610+
begin
611+
value.dup
612+
rescue TypeError
613+
value
612614
end
615+
613616
end
614617
end
615618

0 commit comments

Comments
 (0)