Equivalent to Python3 Pass Team 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 else command. Does Ruby have an equivalent python3 pass command?

+4
source share
4 answers

No, when you want something empty, you do not write anything there Ruby, since it is empty.

def some_function() end 

There is no need for any placeholder, for example, "skip".

+3
source

Your statement is essentially incorrect, since the else statement is optional in Python.

One of the commonly used pass statements is in try / , except when an exception can be ignored.

pass is also useful when defining an API - and you want to defer the actual implementation of classes / functions.

EDIT: Another common use I haven't mentioned is defining a user exception; usually you just redefine the name to distinguish them from standard exceptions.

+6
source

No, ruby ​​does not have a pass statement that you simply won’t write.

 def function if something == 10 end end 

equivalently

 def function: if something == 10: pass 
+2
source

I don’t think you need it in a ruby ​​... and unless otherwise required.

0
source

Source: https://habr.com/ru/post/1439591/


All Articles