Created
March 18, 2011 16:15
-
-
Save mgreenly/876350 to your computer and use it in GitHub Desktop.
recursively walk association.accessor chain and return the result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render(object) | |
receiver = object | |
accessors = accessor.split(".") | |
while accessor = accessors.shift | |
if receiver.class.reflect_on_association(accessor.to_sym) | |
receiver = receiver.send(accessor) | |
else | |
return receiver.send(accessor) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment