What about using Object#try and avoiding the explicit &block argument?This
avoid to instantiate a Proc object *for each* method execution, if any block
isn't passed and the enumerable is empty the VM will raise a LocalJumpError.

module Enumerable
  def else
    self.try(:empty?) ? yield : self
  end
end

Please look at this benchmark (http://gist.github.com/163274) my
implementation is exactly 4x faster ;)

Cheers,
Luca
-- 
lucaguidi.com
twitter.com/jodosha

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to