user1744127
user1744127

Reputation:

Python3 Pass Command Equivalent in Ruby

Python3 has a pass command that does nothing. This command is used in if-constructs because python requires the programmer to have at least one command for else. Does Ruby have an equivalent to python3's pass command?

Upvotes: 4

Views: 1261

Answers (4)

Senthil Kumaran
Senthil Kumaran

Reputation: 56861

No, ruby does not have have pass statement you would simply not write it.

def function
    if something == 10
    end
end

is equivalent to

def function:
    if something == 10:
       pass

Upvotes: 2

codepros
codepros

Reputation: 908

No, when you want something empty, you write nothing in there in Ruby, since it's empty.

def some_function()
end

No need for any placeholder like "pass" for nothing.

Upvotes: 3

volcano
volcano

Reputation: 3582

Your statement is essentially wrong, since else statement is not obligatory in Python.

One of the frequent uses of the pass statement is in try/ except construct, when exception may be ignored.

pass is also useful when you define API - and wish to postpone actual implementation of classes/functions.

EDIT: One more frequent usage I haven't ,mentioned - defining user exception; usually you just override name to distinguish them from standard exceptions.

Upvotes: 6

Toby Hede
Toby Hede

Reputation: 37133

I don't think you need it in ruby ... an if doesn't require an else.

Upvotes: 0

Related Questions