89
stisch
7y

Someone's 3 lines of Ruby that do the same thing as my 30 lines.

Comments
  • 10
    But maybe your program does it better
  • 3
    If yours is more readable then it's better. If the other one is idiomatic then it's better.
  • 2
    @kpenc mine didn't use bitwise operators lol
  • 1
    I once had a project that I had to do in F# and I found a Marge sorry online that took 35 lines. I had no clue how it worked because F# is impossible to read, but it did work.
  • 2
    This is what Ruby is like, though 😊 and it's why the language is so wonderful.

    It's easily readable (generally) and succinct.
  • 1
    @Root I agree, I love Ruby! It seems to always surprise me.. just when I thought I've mastered it I find some awesome trick I didn't know existed
  • 1
    @stisch that happened to me with Rails a few weeks ago. I didn't know about `delegate`! It looks incredibly useful.

    I also didn't know you could chain sugars in Ruby. Ex:

    a=1 and b=2 if c==3

    As you'd expect, it does both assignments if the condition is met, otherwise it does nothing. It can be a bit verbose/ugly on longer lines, but quite useful for readibility on large blocks of similar lines.

    I ended up refactoring this out of my code, but it's neat that it works!
Add Comment