• Die Martin Die@sh.itjust.works
      link
      fedilink
      arrow-up
      8
      ·
      1 year ago

      Lua is the same. Only false and nil are “falsey”.

      I remember I fixed a bug in a mod for Minetest that assumed 0 was false and caused an infinite loop.

    • Synthead@lemmy.world
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      1 year ago

      Yup :) Everything in Ruby inherits Object, too. It’s a really neat language, and when you get accustomed to it, you might wonder why some other languages aren’t written like it.

      For the 0 value being truthy, consider that Ruby is a dynamic language. Imagine if you asked a user how many motorcycles they own. If they answer, you’ll have an Integer. If they don’t, you’ll have nil, from NilClass. 0 is just as valid of an answer as 2, so you can do something like this:

      raise NoResponse unless motorcycles
      
      save_motorcycles(motorcycles)
      
    • DarkenLM@kbin.social
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      And people bash Javascript as if it was the devil when thinks like this exist on other languages.