Solved

Iterate over classes

Posted on 2014-04-10
1
179 Views
Last Modified: 2014-04-14
I have class A and B.  A has many Bs.
B has a field is_visible which can be true or false
I have alot of As as well

I can acquire a set of As by doing the follwoing:

@As = X.find_by...

Need to iterate over all the As, and return Bs where B.is_visble is true.

Best way to do this?
0
Comment
Question by:lcor
1 Comment
 
LVL 10

Accepted Solution

by:
Andrew Doades earned 500 total points
Comment Utility
I've been away from Ruby for way too long!

I think you'll need to put "X" into an array, you can then iterate through the array with array.each, where you can then do something like this:

As.each do
...do stuff...
end

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now