Skip to content

Commit 6c14044

Browse files
committed
Update Thor::Actions#inside to return the value yielded by the block
So that calling code can inspect & use the value.
1 parent 2899621 commit 6c14044

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/thor/actions.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def find_in_source_paths(file)
161161
# to the block you provide. The path is set back to the previous path when
162162
# the method exits.
163163
#
164+
# Returns the value yielded by the block.
165+
#
164166
# ==== Parameters
165167
# dir<String>:: the directory to move to.
166168
# config<Hash>:: give :verbose => true to log and use padding.
@@ -179,7 +181,7 @@ def inside(dir = "", config = {}, &block)
179181
FileUtils.mkdir_p(destination_root)
180182
end
181183

182-
if pretend
184+
result = if pretend
183185
# In pretend mode, just yield down to the block
184186
block.arity == 1 ? yield(destination_root) : yield
185187
else
@@ -189,6 +191,7 @@ def inside(dir = "", config = {}, &block)
189191

190192
@destination_stack.pop
191193
shell.padding -= 1 if verbose
194+
result
192195
end
193196

194197
# Goes to the root and execute the given block.

spec/actions_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ def file
165165
end
166166
end
167167

168+
it "returns the value yielded by the block" do
169+
expect(runner.inside("foo") { 123 }).to eq(123)
170+
end
171+
168172
describe "when pretending" do
169173
it "no directories should be created" do
170174
runner.inside("bar", :pretend => true) {}

0 commit comments

Comments
 (0)