From: Oliver Peng Date: 2008-03-07T00:46:34+09:00 Subject: the value in ensure block is not returned Here is the sample code: irb(main):001:0> def test irb(main):002:1> begin irb(main):003:2* a = 1 irb(main):004:2> b = 2 irb(main):005:2> b irb(main):006:2> ensure irb(main):007:2* a irb(main):008:2> end irb(main):009:1> end => nil irb(main):010:0> test => 2 I am expecting that 1 should be returned by is 2. I also write another code to verify: irb(main):011:0> def test irb(main):012:1> begin irb(main):013:2* a = 1 irb(main):014:2> b = 2 irb(main):015:2> b irb(main):016:2> ensure irb(main):017:2* a irb(main):018:2> puts "hello" irb(main):019:2> end irb(main):020:1> end => nil irb(main):022:0> test hello => 2 So it is obviously that all codes in ensure block have been run. But the return value is always the last value before ensure block. -- Posted via http://www.ruby-forum.com/.