Wednesday, October 28, 2015

raise in Ruby

raise in Ruby will raise whatever exception you rescue in your code. So instead of doing :

raise MyException

you can just do:

raise

Here is a demo:

class MyException < Exception
end

class Foo
  def hi
    raise MyException.new('hello')
  end
end

def tester
  begin
    f = Foo.new
    f.hi
  rescue
    raise
  end
end

tester