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