Skip to content

Commit afa8cb9

Browse files
committedJul 29, 2013
A resque body now returns the last expression evaluated (fixes #302)
1 parent 60d3944 commit afa8cb9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

Diff for: ‎lib/opal/parser.rb

+4
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ def returns(sexp)
382382
sexp
383383
when :rescue
384384
sexp[1] = returns sexp[1]
385+
386+
if sexp[2] and sexp[2][0] == :resbody and sexp[2][2]
387+
sexp[2][2] = returns sexp[2][2]
388+
end
385389
sexp
386390
when :ensure
387391
sexp[1] = returns sexp[1]

Diff for: ‎spec/opal/language/rescue_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'spec_helper'
2+
3+
class RescueReturningSpec
4+
def single
5+
begin
6+
raise "ERROR"
7+
rescue
8+
:foo
9+
end
10+
end
11+
12+
def multiple
13+
begin
14+
raise "ERROR"
15+
rescue
16+
to_s
17+
:bar
18+
end
19+
end
20+
end
21+
22+
describe "The rescue keyword" do
23+
it "returns last value of expression evaluated" do
24+
RescueReturningSpec.new.single.should == :foo
25+
RescueReturningSpec.new.multiple.should == :bar
26+
end
27+
end

0 commit comments

Comments
 (0)
Please sign in to comment.