Are there any exceptions to Ruby convention of boolean methods having a question mark (?) -


For those methods that return the Boolean values, it seems normal to end the call, but in some code I saw Is it not done continuously, for example, do some tasks like create and save not? Finally I have seen some code.

Is this bad behavior / incompatible? Should it be everywhere where a boolean is returned? Or is it sometimes dropped?

activation code save does not ask a question, it only performs one task And gives the status of requested action returns value (i.e. status) boolean is useless.

Like Array # include? or String # start_with? Ask questions like on their name. are suffixes.

So this is not the return value, which determines whether the name of the method ends with the question mark, this method is intended: if calling the method is primarily a yes / ask a question So it receives a question mark; If you call the method and do something else primarily, then it does not get any question marks even if it has to return the boolean value.


Of course the reality is not that easy. Returns integer to

returns zero or integer and to confuse matters Both of these questions ask - "Is the size of file with the name X ?" - The only difference is that File.size? returns zero if the file does not exist or the size is zero (embarrassment) while there is no specific behavior for files in File.size (But no file # size? ) as an example method, in the same category, file # size same question as File.size and File.size? There is no question mark on .

Then we have float :

  • And many other methods that ask questions but any ? is not a suffix.
  • Who asks a yes / no question, but zero , returns to -1 , or +1 .
  • And yes / no questions are asked and the true or false come back.

    There are other examples (such as weirdly designated defined? operator, versus vs, ...) where a ? - The original does not return a boolean value, but they are exceptions and are standing because they are incompatible with normal basic behavior.

    We can also bring attr_reader if you say:

      attr_reader: pancakes   

    then You get a pancakes method that you can use to ask questions " pancakes What is the value of the property?" Note that to ask you this question < code> pancakes? The method does not get, just get the pancakes accessor method.

    ? The methods in the core are somewhat incompatible, but leaning toward numbers "answer a question or yes do not answer". As far as the non-core code is concerned, people can do whatever they want, there is no doubt that there is a lot of discrepancy in it.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -