tag:blogger.com,1999:blog-24779679.post4404196954888240574..comments2023-05-19T03:27:14.189-07:00Comments on Thoughts: Writing Prettier Ruby Code with instance_evalmahmoudhttp://www.blogger.com/profile/09457586853819956435noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-24779679.post-24828011456757072802009-01-29T02:07:00.000-08:002009-01-29T02:07:00.000-08:00This seems to be not so messy at all:a = [1, 2, 3,...This seems to be not so messy at all:<BR/><BR/>a = [1, 2, 3, 4, 5, 6, 7, 8]<BR/>a.size<BR/>a.sum rescue puts("Method not found")<BR/>a.average rescue puts("Method not found")<BR/><BR/>def a.sum<BR/> inject(0){|a,e| a + e}<BR/>end<BR/> <BR/>def a.average<BR/> sum / size<BR/>end<BR/> <BR/>a.averageAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-24779679.post-5139309206520689372008-11-17T04:56:00.000-08:002008-11-17T04:56:00.000-08:00You are welcome Ahmed,actually i used this method ...You are welcome Ahmed,<BR/><BR/>actually i used this method in a piece of code that would have looked very messy without it..<BR/><BR/>i'll probably be talking about it soon isAmahmoudhttps://www.blogger.com/profile/09457586853819956435noreply@blogger.comtag:blogger.com,1999:blog-24779679.post-38375778577534397232008-11-17T03:11:00.000-08:002008-11-17T03:11:00.000-08:00This is really cool :)and you are so right about t...This is really cool :)<BR/>and you are so right about the usage, it is very handy<BR/><BR/>Thanks for the tip :)Anonymousnoreply@blogger.com