tag:blogger.com,1999:blog-924015769731377256.post2245988294709810153..comments2024-02-12T21:20:40.717-08:00Comments on Paul's Software Blog: Ruby Metaprogramming with class_evalUnknownnoreply@blogger.comBlogger9125tag:blogger.com,1999:blog-924015769731377256.post-23306610371678860872014-06-16T06:29:24.663-07:002014-06-16T06:29:24.663-07:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/12583223916292891601noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-15296972817238431032014-06-15T09:30:57.464-07:002014-06-15T09:30:57.464-07:00I think the spec is asking you to provide the hist...I think the spec is asking you to provide the history but without the current (last) value.<br />You probably need to strip the last value off in order to pass the test.Martin Programmerhttps://www.blogger.com/profile/00909132322293763876noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-64655886810569596342014-05-22T12:26:53.055-07:002014-05-22T12:26:53.055-07:00Great post indeed !
I'm trying to use it as p...Great post indeed ! <br />I'm trying to use it as part of CS169.1x Engineering Software as a Service course, and I'm getting the following error in the RSpec tests : <br /><br />Failure/Error: obj1.foo_history.should == [nil, :x]<br /> expected: [nil, :x]<br /> got: [nil, :x, :y] (using ==) <br />expected: [nil, "x"]<br /> got: [nil, "x", "y"] (using ==) <br />.<br />.<br />.<br />.<br /><br />this happens for all the tests, It see,s like the out put should not include the current value . <br /><br />any idea how can I fix it ? Anonymoushttps://www.blogger.com/profile/09206935674438020142noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-28467420623441016782014-05-18T11:07:57.693-07:002014-05-18T11:07:57.693-07:00Thank you this is so preciousThank you this is so preciousAnonymoushttps://www.blogger.com/profile/09662863529797778356noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-45132826985407926642013-11-28T08:18:55.401-08:002013-11-28T08:18:55.401-08:00This was wonderful. Thanks!This was wonderful. Thanks!Unknownhttps://www.blogger.com/profile/01231508476820141555noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-17687384264917906192013-06-01T17:52:11.989-07:002013-06-01T17:52:11.989-07:00Great post! I'm learning Ruby and this was bot...Great post! I'm learning Ruby and this was both clear and amazing, congratulations.Anonymoushttps://www.blogger.com/profile/06568348347188417139noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-39381354948433940942012-10-10T03:35:19.006-07:002012-10-10T03:35:19.006-07:00When def #{attr_name}=(attr_name) is called it cre...When def #{attr_name}=(attr_name) is called it creates a method for the class with the attr_name passed to it. It is just a setter method in Ruby.<br /><br />For example if you create a class named foo and add an accessor to it by this:<br />class Foo<br /> attr_accessor_with_history :bar<br />end<br /><br />the above code will be called like this:<br />def bar=(attr_name)<br /> @bar = attr_name<br /> unless @bar_history #this makes sure the bar_history is created<br /> @bar_history = []<br /> @bar_history << nil<br /> end<br /> @bar_history << @bar<br />end<br /><br />And if you create another accessor:<br />class Foo<br />attr_accessor_with_history :baz<br />end<br /><br />just replace the bar in the above code with baz.<br />This way you will access to the previous items that have been assigned to the Foo instance with the variable name added _history behind it.<br />I think Ruby does not allow spaces in the setter method, that's just the way it is.<br /><br />Edit: Couldn't edit my previous comment, so I had to delete it and repost.Anonymoushttps://www.blogger.com/profile/06006166358060347772noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-79964597171851953452012-10-10T03:31:19.498-07:002012-10-10T03:31:19.498-07:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/06006166358060347772noreply@blogger.comtag:blogger.com,1999:blog-924015769731377256.post-39714084964346878942012-10-07T15:59:29.784-07:002012-10-07T15:59:29.784-07:00I don't really understand what is happening at...I don't really understand what is happening at:<br />def #{attr_name}=(attr_name) <br /><br />For one, what does this mean? It seems that if I were to make a class call Foo and make call attr_accessor_with_history :bar, it would evaluate to<br />def bar=(attr_name), but I don't know what that means?<br />Secondly, I tried <br />def #{attr_name} = (attr_name)<br />and it doesn't work. Why does the spaces matter? Edward Wanghttps://www.blogger.com/profile/08391952248890663913noreply@blogger.com