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 Is this bad behavior / incompatible? Should it be everywhere where a boolean is returned? Or is it sometimes dropped? activation code Like 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 returns Then we have There are other examples (such as weirdly designated We can also bring then You get a create and
save not? Finally I have seen some 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.
Array # include? or
String # start_with? Ask questions like
on their name. are suffixes.
integer to
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 .
float :
? is not a suffix.
zero ,
returns to -1 , or
+1 .
true or
false come back.
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.
attr_reader if you say:
attr_reader: pancakes
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
Post a Comment