C
coderrr
Hey I just put together a list of stuff I totally wish Ruby had and I
think would make a lot of people's lives better.
In the order of importance:
1) rescue/ensure available in all blocks
arr.each do |e|
e.do_something
rescue MyException
p :doh!
ensure
p :every_time!
end
It's totally gross to have to use begin/end blocks inside of do/end.
Is there any reason why it's not possible to do this?
2) two line if/while statements (like c):
if true
p :true
p :im_outside_of_if
I'm a huge fan of one liners like:
x if y
... but sometimes it just doesn't fit on one line and you need to do
if x ... end. Needing an extra line for that end really really
sucks. Shouldn't we be able to do it C style and save a line?
3) rescue a specific exception type inline
do_something_dangerous rescue(SpecificException) p :OH_NO!
s = (do_something_that_times_out rescue(Timeout::Error) nil)
Timeout::Error is the big reason for wanting this one since it doesn't
inherit from StandardError. But there are many other cases in which
it would be nice too.
These next two go together and I don't really care _that_ much about
them.
4) inline do/while statements:
d = s.read dowhile d
I dislike that the inline while functions exactly like a normal while
loop, checking the while condition before the initial run. I would
prefer if it acted like a begin ... end while loop, checking the
while condition after the first iteration. I don't really care to
change how the while keyword works, but it'd be nice if a new keyword
acted this way, maybe dowhile? I haven't thought up a good name yet.
5) more concise (inline) syntax for begin...end
begin ret = a.delete something end while ret <--- gross
begin { ret = a.delete something } while ret
or: do { ... } while
An alternative to #4 is just to make writing begin/end blocks much
nicer. Perhaps an inline version like: do { } Then it would be
simple to get the while functionality I desire.
Anyone with me on this stuff?? I would _really_ love to see #1-3 in
Ruby 1.9.
think would make a lot of people's lives better.
In the order of importance:
1) rescue/ensure available in all blocks
arr.each do |e|
e.do_something
rescue MyException
p :doh!
ensure
p :every_time!
end
It's totally gross to have to use begin/end blocks inside of do/end.
Is there any reason why it's not possible to do this?
2) two line if/while statements (like c):
if true
p :true
p :im_outside_of_if
I'm a huge fan of one liners like:
x if y
... but sometimes it just doesn't fit on one line and you need to do
if x ... end. Needing an extra line for that end really really
sucks. Shouldn't we be able to do it C style and save a line?
3) rescue a specific exception type inline
do_something_dangerous rescue(SpecificException) p :OH_NO!
s = (do_something_that_times_out rescue(Timeout::Error) nil)
Timeout::Error is the big reason for wanting this one since it doesn't
inherit from StandardError. But there are many other cases in which
it would be nice too.
These next two go together and I don't really care _that_ much about
them.
4) inline do/while statements:
d = s.read dowhile d
I dislike that the inline while functions exactly like a normal while
loop, checking the while condition before the initial run. I would
prefer if it acted like a begin ... end while loop, checking the
while condition after the first iteration. I don't really care to
change how the while keyword works, but it'd be nice if a new keyword
acted this way, maybe dowhile? I haven't thought up a good name yet.
5) more concise (inline) syntax for begin...end
begin ret = a.delete something end while ret <--- gross
begin { ret = a.delete something } while ret
or: do { ... } while
An alternative to #4 is just to make writing begin/end blocks much
nicer. Perhaps an inline version like: do { } Then it would be
simple to get the while functionality I desire.
Anyone with me on this stuff?? I would _really_ love to see #1-3 in
Ruby 1.9.