... or perhaps even or_if_blank. :-)
Ryan
On Thu, Aug 6, 2009 at 11:02 AM, John W. Long wrote:
>
> On Aug 6, 2009, at 4:10 AM, Paul wrote:
> > module Enumerable
> > def else(&block)
> >self.respond_to?('empty?') && self.empty? ? yield : self
> > end
> > end
>
>
> Wouldn't this method b
On Aug 6, 2009, at 4:10 AM, Paul wrote:
> module Enumerable
> def else(&block)
>self.respond_to?('empty?') && self.empty? ? yield : self
> end
> end
Wouldn't this method be better named "ifempty"? If you call it "else"
it makes me wonder where the other part of the clause is? Certainly i
much better - thank you!
--~--~-~--~~~---~--~~
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
Just updated the benchmark (http://gist.github.com/163274), tried to solve
the issue using #any? instead of #try, but isn't fast for filled arrays:
module Enumerable
def else
not any? ? yield : self # don't try this at home
end
end
Luca
--
lucaguidi.com
twitter.com/jodosha
--~--~
Ticket: https://rails.lighthouseapp.com/projects/8994/tickets/1950
Mike
On Aug 6, 2009, at 7:50 AM, Eloy Duran wrote:
> Yeah creating a proc every time isn't needed and much cleaner this
> way. I do think that it's better to use #blank? as was used in
> Ryan's patch. Still waiting for that t
Ugh, scrap that, I need sleep.
On Aug 6, 2009, at 2:50 PM, Eloy Duran wrote:
> I do think that it's better to use #blank?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to th
Yeah creating a proc every time isn't needed and much cleaner this
way. I do think that it's better to use #blank? as was used in Ryan's
patch. Still waiting for that ticket :)
Eloy
On Aug 6, 2009, at 2:44 PM, Ryan Angilly wrote:
> Similar discussion from an older ticket:
> https://rails.li
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 wrote:
> What about using Object#try and avoiding the explicit &block argument?This
> avoid to instantiate a Proc object
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
e
I like it. Is there a ticket and patch that I can verify and add my +1?
Eloy
On Aug 6, 2009, at 10:10 AM, Paul wrote:
>
> i made a suggestion for this within lighthouse.
>
> Pratik said: "This looks interesting. But I'm not sure if this pattern
> belongs to the core or not. You should probably
10 matches
Mail list logo