Why are exclamation marks used in Ruby methods?

后端 未结 10 2190
小蘑菇
小蘑菇 2020-11-22 06:01

In Ruby some methods have a question mark (?) that ask a question like include? that ask if the object in question is included, this then returns a

10条回答
  •  故里飘歌
    2020-11-22 06:28

    This naming convention is lifted from Scheme.

    1.3.5 Naming conventions

    By convention, the names of procedures that always return a boolean value usually end in ``?''. Such procedures are called predicates.

    By convention, the names of procedures that store values into previously allocated locations (see section 3.4) usually end in ``!''. Such procedures are called mutation procedures. By convention, the value returned by a mutation procedure is unspecified.

提交回复
热议问题