Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
steveklabnik
on Aug 14, 2010
|
parent
|
context
|
favorite
| on:
Strangest language feature
You can use {} instead of do/end if you'd like.
mkramlich
on Aug 14, 2010
[–]
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.
steveklabnik
on Aug 14, 2010
|
parent
|
next
[–]
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
ShardPhoenix
on Aug 14, 2010
|
parent
|
prev
[–]
I find it easier to type "end" than "}".
mkramlich
on Aug 15, 2010
|
root
|
parent
[–]
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: