This project is archived and is in readonly mode.
ActiveSupport: alternative Block execution on empty Enumerable
-
Pratik
- State changed from new to wontfix
This looks interesting. But I'm not sure if this pattern belongs to the core or not. You should probably spark a discussion in the core ML - http://groups.google.com/group/rubyonrails-core
Thanks.
-
Luca Guidi
Attached a patch for a more efficient implementation: http://gist.github.com/163274
-
Eloy Duran
@Luca: In the docs you miss the 'do' keyword: “end.else” => “end.else do”. Besides that; verified and I like it! +1
-
Luca Guidi
Thanks Eloy, I just fixed the rdoc issue and added a couple of test cases.
-
blatyo
I could definitely see myself using something like this. I would definitely change the name from else though. It's bad practice to use keywords as method names and else provides no context when used by itself. +1 (with some changes)
-
Luca Guidi
@blatyo which name do you suggest?
-
Paul
i do not think the use of else is bad within this context. it reads nice:
with.each do this end.else do that end
using it "standalone" does not make much sense i.m.O.
elements.else do
... endan
if elememts.blank?
... endis and will be better - regardless of the naming of the method...
-
Evgeniy Dolzhenko
My take on it is:
when_blank
