tag:blogger.com,1999:blog-4704664917418794835.post1659853267171023582..comments2023-07-01T05:41:30.469-07:00Comments on Headius: Adding Annotations to JRuby Using Rubyheadiushttp://www.blogger.com/profile/15717357218364947795noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4704664917418794835.post-43953019569827535582007-05-27T20:28:00.000-07:002007-05-27T20:28:00.000-07:00Hmm, I would prefer a syntax like this:p MyBean.an...Hmm, I would prefer a syntax like this:<br><br>p MyBean.annotations[:foo]<br><br>So,<br><br>class JPABean<br>self.attr_accessor :annotations<br>endDaniel Spiewakhttp://www.blogger.com/profile/17323566514229790079noreply@blogger.comtag:blogger.com,1999:blog-4704664917418794835.post-31030407569218287292007-05-28T18:39:00.000-07:002007-05-28T18:39:00.000-07:00@zimbaVery nice! That should avoid overwriting th...@zimba<br><br>Very nice! That should avoid overwriting the annotations. What if we expand the syntax a bit more like this:<br><br>def self.anno(*annotations)<br>(@@last_annotation ||= {}).merge! annotations<br>end<br><br>So this should let us do this:<br><br>anno :anno1 => 'My test anno1', :anno2 => 'My test anno2'<br><br>Also, we could expand this just a bit further, and alias the method:<br><br>alias :annotate, :anno<br><br>(since I rather like a full method name, rather than a cryptic abbreviation)Daniel Spiewakhttp://www.blogger.com/profile/17323566514229790079noreply@blogger.comtag:blogger.com,1999:blog-4704664917418794835.post-11243443648164316472007-05-29T06:04:00.000-07:002007-05-29T06:04:00.000-07:00@daniel: This bit:anno :anno1 => 'My test a...@daniel: This bit:<br><br>anno :anno1 => 'My test anno1', :anno2 => 'My test anno2'<br><br>Would actually just make `annotations' be an array with one hash. To achieve the effect you were probably going for, you'd need to do:<br><br>anno { :anno1 => 'My test anno1' }, { :anno2 => 'My test anno2' }<br><br>Where the {}s would be optional on the second hash. Otherwise, the original definition of anno would still capture both annotations as part of the same hash.<br><br>Looks pretty rockin' :-)Antoniohttp://www.blogger.com/profile/00685775039560712665noreply@blogger.comtag:blogger.com,1999:blog-4704664917418794835.post-50496132808915160322007-05-29T09:56:00.000-07:002007-05-29T09:56:00.000-07:00@antonioNope, I'm going for this:anno {:anno1 ...@antonio<br><br>Nope, I'm going for this:<br><br>anno {:anno1 => 'My Test anno1', :anno2 => 'My Test anno2'}<br><br>(curly-braces are obviously optional) Which, come to think of it would require a slightly different method signature:<br><br>def self.anno(annotation)<br>(@@last_annotation ||= {}).merge!(annotation)<br>end<br><br>Since annotation would then be a proper, multi element hash (something I sort of failed to realize on my first pass through the comments). :-) So, zimbatm was right all along...Daniel Spiewakhttp://www.blogger.com/profile/17323566514229790079noreply@blogger.comtag:blogger.com,1999:blog-4704664917418794835.post-77148781430897534532007-05-30T01:16:00.000-07:002007-05-30T01:16:00.000-07:00"JRuby doesn't support annotations becaus...<i>"JRuby doesn't support annotations because Ruby doesn't support annotations."</i><br><br>This sounds like a jealousy in respect to groovy :)Anton Arhipovhttp://www.blogger.com/profile/11951065633319406772noreply@blogger.comtag:blogger.com,1999:blog-4704664917418794835.post-48854519348610046752007-05-31T21:12:00.000-07:002007-05-31T21:12:00.000-07:00Good starter implementation. Unfortunately it gets...Good starter implementation. Unfortunately it gets more complex when defining annotations in modules. Facets' Annotations addressed this. Will that work in JRuby? NOTE The lib will get an official independent release soon. That'll be a good time to try it out.tea42http://www.blogger.com/profile/02848516783203845093noreply@blogger.com