Hacker News new | past | comments | ask | show | jobs | submit login

You can use {} instead of do/end if you'd like.



great! wonder why most people don't use it? I keep seeing "end" in almost every chunk of Ruby code I see on the web.


The general convention is that {} is for one line blocks, and do/end for multiline.

    [1,2,3].each{|n| puts n }
versus

    [1,2,3].each do |n|
      m = n + 1
      puts m
    end
The reason? do/end is much prettier than {}, but {} is really nice for chaining...

    [1,3,2].collect{|n| n + 2 }.sort


I find it easier to type "end" than "}".


but it's 3 characters versus 1. is it easier because you don't have to hit SHIFT?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: