Hi, i was wondering whether there was a better way to write something in this type of format: def foo if x somefunction ..find(:all, :conditions => a + b + c + d) else samefunction ..find(:all, :conditions => a + b + c) end end into something a lot shorter like: def foo somefunction find(:all, :condtions => a + b + c, :with_exclusive_scope?? => d ) end or something with that kind of edge... is there some railsy thing like this? thanks in advance -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
question <rails-mailing-list@...> writes:> Hi, > i was wondering whether there was a better way to write something in > this type of format: > > def foo > if x > somefunction > ..find(:all, :conditions => a + b + c + d) > else > samefunction > ..find(:all, :conditions => a + b + c) > end > end > > into something a lot shorter like: > > def foo > somefunction > find(:all, :condtions => a + b + c, :with_exclusive_scope?? => d ) > endI wrote a class a couple of days ago for just this kind of thing: http://pastie.caboo.se/12591 use it like: def foo conditions = Conditions.new conditions << ["a = ?", a] conditions << ["b = ?", b] conditions << ["c = ?", c] conditions << ["d = ?", d] if x find(:all, :conditions => conditions) end Gareth --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
very very cool...thanks! sure i''ll put this to good use. . . thx -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Of course, there''s always pre-generation: def foo conditions = a + b + c conditions += d if x somefuction find(:all, :conditions => conditions) end Jason On 9/12/06, Gareth Adams <gareth.adams-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > question <rails-mailing-list@...> writes: > > Hi, > > i was wondering whether there was a better way to write something in > > this type of format: > > > > def foo > > if x > > somefunction > > ..find(:all, :conditions => a + b + c + d) > > else > > samefunction > > ..find(:all, :conditions => a + b + c) > > end > > end > > > > into something a lot shorter like: > > > > def foo > > somefunction > > find(:all, :condtions => a + b + c, :with_exclusive_scope?? => d ) > > end > > I wrote a class a couple of days ago for just this kind of thing: > > http://pastie.caboo.se/12591 > > use it like: > > def foo > conditions = Conditions.new > conditions << ["a = ?", a] > conditions << ["b = ?", b] > conditions << ["c = ?", c] > conditions << ["d = ?", d] if x > > find(:all, :conditions => conditions) > end > > Gareth > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---