Rails is a ghetto

if ra[:address] && !ra[:address].nil?

  • 5
    There is the present? Method that checks for existence and not nil:

    if ra[:address].present?
  • 3
    ra[:address] is already falsy if it's nil, the second check is redundant 👀
  • 0
    @TeeSeal this will throw an error if no key with that name exists though.
  • 3
    @fuckwit Hashes do not throw errors for keys that do not exist. They return nil, or whatever default you provide.

    @Puroguramingu Your variable naming is ghetto.
  • 1
    Do. Not. ++. Beg.
    They're easy to come by.
    What the hell.
  • 1
    @Root yeah remembered that after it was too late to edit the comment.

    This method is mainly for checking if it exists and has a value that is not nil, empty string, whitespace string, empty array/hash or false.
  • 1
    @fuckwit Yap. #present? is probably the method I miss most when working on Ruby (non-Rails) projects.
  • 0
    @Root now hang on just a sec lass, that's certainly not my code.
  • 0
    @Puroguramingu Glad, because it's pretty smelly. 😋

    (Also, I can't see the image.)
  • 0
    @root haha I wouldn't be caught writing that. The images should be working again hopefully.
Add Comment