Ruby - Using class_eval to define methods

后端 未结 3 2010
情深已故
情深已故 2020-12-23 10:45

I\'m doing the SaaS Stanford class, trying to do Part 5 of this assignment

I\'m having a really hard time grasping this concept, this is what I\'ve attempted to do:<

3条回答
  •  醉酒成梦
    2020-12-23 11:10

    With regard to what you've done you're actually on the cusp of the solution. It's just that #{attr_name}_history doesn't exist in your code. You will need to create an instance variable and set it to nil if it doesn't exist. What you have already should handle pushing into the array if it does exist.

    There are several ways to do that. One way is if defined? @#{attr_name}_history DoStuffHere

提交回复
热议问题