Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChris Ward
12,129 PointsRUBY: What do I do if I need to use references in my program?
I really like the simplicity of Ruby, but now that I have taken on a real world project, I'm wondering if simplicity is also its fatal flaw...
Ok, so I am writing two classes. The first class is called SimpleCondition. It mimics some unary and binary conditional evaluation operations; for instance, the method csc_beq (Create SimpleCondition: Binary EQuality) takes two object references to test the equality of objects A and B (A == B) at various future points in the program and does something (optionally) if the condition is true by calling a passed in block reference, along with other information specific to my design. The second class is called ComplexCondition. It is just compound cases of SimpleCondition. So how am I supposed to keep track of these two objects that change throughout the program? If I use the = assignment, it might copy the object reference, or the = might be overridden...I simply have no way to tell...and that's a problem I don't know how to overcome.
At least PHP has the =& operator, and assignment of reference can be guaranteed, but there doesn't seem to be anything similar in Ruby. I'm stumped and don't know how to proceed. Hopefully someone has some suggestions...
1 Answer
Chris Ward
12,129 PointsI'm told that the assignment operator cannot be overridden. Can someone confirm this?