... or perhaps even or_if_blank.   :-)

Ryan

On Thu, Aug 6, 2009 at 11:02 AM, John W. Long <[email protected]> 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 be better named "ifempty"? If you call it "else"
> it makes me wonder where the other part of the clause is? Certainly it
> reads nicely in expressions like this:
>
> results.each do |x|
>   puts x
> end.else do
>   puts "none found"
> end
>
> But each isn't exactly an if statement. I can guess what it means in
> the context above, but it doesn't read right.
>
> And what if you wanted to use it on its own?
>
> results.else do
>   puts "none found"
> end
>
> In the case above it makes little sense. "ifempty" seems to read a
> little better.
>
> --
> John Long
> http://recursivecreative.net
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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