Equivalent of “pass” in Ruby

user1251007 picture user1251007 · Nov 19, 2012 · Viewed 31.1k times · Source

In python there is a pass keyword for defining an empty function, condition, loop, ... Is there something similar for Ruby?

Python Example:

def some_function():
    # do nothing
    pass

Answer

Jörg W Mittag picture Jörg W Mittag · Nov 19, 2012

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.