Similar discussion from an older ticket: https://rails.lighthouseapp.com/projects/8994/tickets/1815-patch-add-or_if_blank-to-object
On Thu, Aug 6, 2009 at 8:38 AM, Luca Guidi <guidi.l...@gmail.com> wrote: > 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---