7 ms·
Its in the issue comments def foo? Object.new end foo?.class since "foo?" is a valid method it would conflict with "?." Edit: with ".?" lo
by griffinheart 11y ago
Its in the issue comments
def foo?
Object.new
end
foo?.class
since "foo?" is a valid method it would conflict with "?."
Edit: with ".?" looks like "foo?.?class"
Edit 2: side note, this would never pass a code review, the expectation of "foo?" is that it returns true/false.
- tom-lord 11y ago> this would never pass a code review, the expectation of "foo?" is that it returns true/false. 95% of the time, yes. However, the "official" rule is simply that such methods must return a value that can be EVALUATED as true/false. There are plenty of methods in the ruby core/standard library which end in a "?" but do not return true/false, such as: * File#size (http://ruby-doc.org/core-2.2.3/File.html#method-c-size-3F http://ruby-doc.org/core-2.2.3/File.html#method-c-size-3F) returns Integer or nil. * Integer#nonzero? (http://ruby-doc.org/core-2.2.0/Numeric.html#method-i-nonzero-3F http://ruby-doc.org/core-2.2.0/Numeric.html#method-i-nonzero...) returns self or nil. This misunderstanding of what "?" methods are allowed to return is an ongoing problem in the community, e.g. https://github.com/rails/rails/issues/20110 https://github.com/rails/rails/issues/20110