Equivalent of “pass” in Ruby

No, there is no such thing in Ruby. If you want an empty block, method, module, class etc., just write an empty block:

def some_method
end

That's it.

In Python, every block is required to contain at least one statement, that's why you need a "fake" no-op statement. Ruby doesn't have statements, it only has expressions, and it is perfectly legal for a block to contain zero expressions.


nil is probably the equivalent of it:

def some_function
    nil
end

It's basically helpful when ignoring exceptions using a simple one-line statement:

Process.kill('CONT', pid) rescue nil

Instead of using a block:

begin
    Process.kill('CONT')
rescue
end

And dropping nil would cause syntax error:

> throw :x rescue
SyntaxError: (irb):19: syntax error, unexpected end-of-input
        from /usr/bin/irb:11:in `<main>'

Notes:

def some_function; end; some_function returns nil.

def a; :b; begin; throw :x; rescue; end; end; a; also returns nil.