• Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    spoiler flag...

  • Custom User Avatar

    The de-facto community style guide for Ruby suggests using parens if the method accepts paramters and leaving off the parens if the method takes no parameters.

  • Custom User Avatar

    both are equivalent because (roughly) x != None <=> x != False <=> x == True <=> bool(x) so if one applies ("bool"), != None has to be considered the same here.

    Again, the recommandation is here to avoid, imo, that beginners fall in the trap I mentionned above. I don't say there are no other reasons, tho. Just that I don't see them right now.

  • Custom User Avatar

    Sticking to conventions is good but you need to understand the reasons for them. That convention is meaningful only when you can have some ambiguity between None and other "falsy" values. Like:

    sum(map(bool, (1,0,None,2)))
    >>> 2
    
    sum(x is not None for x in (1,0,None,2))
    >>> 3
    

    But considere the current case: you receive either None or an object whose boolean equivalent won't be "falsy" (even if it "holds" an empty string). So there is no ambiguity there, so you can work with either method/approach you want, that won't change a thing.

    Style guides are just conventions. Use them wisely, not blindly. ;)

    (note: about best practices, what is that ^ doing in there??? ;p )