Doing things like this, it may be easier to use the named placeholders
version - so your example will look like:

a = ["(modulable_type=:modulable_type) AND (parent_id=:parent_id) AND
(status=:status)",{:modulable_type => "Task", :parent_id =>
"2", :status => "20"}]
b = ["(tasks.due_date=:due_date)", {:due_date => "2009-08-22"}]

Then c is as simple as:

c = ["#{a[0]} AND #{b[0]}", a[1].merge(b[1])]

Note: this will fail in creative ways if you have parameters in a and
b that are supposed to have different values but have the same name,
so don't do that. :)

--Matt Jones

On Aug 23, 4:23 am, Colin Law <[email protected]> wrote:
> 2009/8/23 tispratik <[email protected]>:
>
>
>
> > Can anyone help me on the following?
>
> > I have the following 2 arrays, how do i get c as a result of a and b.
> > The elements should be in the specified order.
>
> > a = ["(modulable_type=?) AND (parent_id=?) AND
> > (status=?)","Task","2","20"]
> > b = ["(tasks.due_date=?)", "2009-08-22"]
>
> > c = ["(modulable_type=?) AND (parent_id=?) AND (status=?) AND
> > (tasks.due_date=?)","Task","2","20","2009-08-22"]
>
> I have encountered exactly this problem and realised that, though this
> is solvable, it is better (if possible) to build the arrays
> differently in the first place.  I realise this may not be possible
> for you but if you change the original conditions building so that it
> builds two arrays of the form
> conditions = ["(modulable_type=?)","(parent_id=?)"]
> and
> values = ["Task","2"] and so on, so just adding each condition and
> value as they arise, then the required result is
> c = [conditions.join(" AND ")] + values
>
> No doubt there are even better ways, and it may not match your needs
> anyway, but for me it worked well as I was working through a number of
> options building the conditions as I went.
>
> Colin
>
> and b similarly
> Then c = (a+b).collect(
--~--~---------~--~----~------------~-------~--~----~
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 [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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to