by myndpage · 13y ago · 0 comments
That's not true. Predicates methods returns Truthy or Falsey values. Not necessarily booleans. See http://blog.leshill.org/blog/2012/03/25/a-question-of-truth....
Original intent aside, if your language is prided on convention, then it has to be open to the convention changing.
Btw: The mantra "convention over configuration" is a rails mantra and not a ruby mantra.
Also, I never said "convention over configuration," since there's nothing to configure here. I was talking specifically about the convention of what a "?" should return. In that same quote Matz also says that predicates typically return a boolean value, but it's not required. That seems to both imply and endorse a convention.
Sure. The convention endorsed is "should, but not required". That's exactly what happens. A pattern I see often is something along the lines of
def ssl?(url)
url.match /^https/
end
which returns nil in the case the url doesn't start with https and a matchdata object if it does. jruby-1.6.8 :092 > def ssl?(url)
jruby-1.6.8 :093?> url.match /^https/
jruby-1.6.8 :094?> end
=> nil
jruby-1.6.8 :095 > ssl? "https://google.com"
=> #<MatchData "https">
jruby-1.6.8 :096 > ssl? "http://google.com"
=> nil