How can I save the value of an instance method?
问题 If I have a list of items, and for every one of them I'm calling an instance method, how can I save the value of the method and prevent it from being calculated every time it's called? Say I have two items: <% if method_true %> do something <% end %> <% if method_true %> do something else <% end %> If method_true == true, how can I just pass the value true through the two ifs instead of calculating it every time? 回答1: I'm sure there's a more sophisticated answer out there, but for my app I