What is the purpose of “!” and “?” at the end of method names?

后端 未结 5 2064
生来不讨喜
生来不讨喜 2020-12-04 07:28

Sometimes I see methods in Ruby that have \"?\" and \"!\" at the end of them, e.g:

name = \"sample_string\"
name.reverse
name.reverse!
name.is_binary_data?
<         


        
5条回答
  •  [愿得一人]
    2020-12-04 07:50

    In Ruby the ? means that the method is going to return a boolean and the ! modifies the object it was called on. They are there to improve readability when looking at the code.

提交回复
热议问题