• morrowind@lemmy.ml
    link
    fedilink
    arrow-up
    3
    arrow-down
    1
    ·
    edit-2
    1 year ago

    Not in ruby, the for loop was initially put there to make it friendly for people from other languages and is discouraged. It’s just syntax sugar on top of each.

    By shortand version I meant

    array.each(&:to_s)
    

    (although in this case I’m not calling puts anymore)

    edit: lemmy keeps putting the & there, but you know what I mean

    • AnomalousBit@programming.dev
      link
      fedilink
      arrow-up
      1
      arrow-down
      2
      ·
      1 year ago

      Not in Ruby

      It’s valid syntax, it’s part of Ruby. It’s easy to read and familiar across many languages. Write what you want to write, I’m not sure why you feel the need to finger wag.