From: Robert Klemme Date: 2007-05-17T20:30:05+09:00 Subject: Re: Some Ruby Features missing... On 16.05.2007 20:49, edlich@gmail.com wrote: > To start a new Ruby Project I need some more features that I know > partially from Java: > > 1. Does Ruby support Annotations? Or is there another cool way to do > this > without changing the class itself? > -> I need to tell reflection to do something special with the class. You can implement annotations yourself with some meta programming. class Module def annotate(meth, *info, &code) (@annotations || = Hash.new {|h,k| h[k]})[meth]=[info, code] end end class Foo annotate :bar, "useful method" annotate :foo do 3+4 end end And later do with @annotations whatever you want. > 2. Can I modify the getter of any instance var?! > -> E.g. if an attribute defines attr_accessor, can I change the getter > at > runtime to do magic aspect stuff around the real get call? Yes. You can even redefine attr_accessor to generate different accessors in the first place although that's not a good idea as this will affect a lot of code. But you can define your own attr_accessor to generate whatever code you need. > 3. Can we define new Keywords in Ruby? > -> I am thinking of somthing like this: Define a block containing some > real code and some useless keywords. Then I want to pass the block, > e.g. convert it to_s and read the real code and the keywords. > The keywords itself shall be ignored by ruby but can be parsed by me. > (I always thought this would be a basic feature to build a DSL... > but obviously real gurus can do without this...) I am not sure what you are at here. You can always define methods for classes that behave keyword like, and you can even store the block for later reference class Module def ignored @ignored || [] end private def ignore(&b) (@ignored ||= []) << b end end irb(main):052:0> class Foo irb(main):053:1> ignore do irb(main):054:2* 1 + 2 irb(main):055:2> end irb(main):056:1> end => [#] irb(main):057:0> Foo.ignored.map {|code| code.call} => [3] > 5. Is there a (free) UML modelling Tool for Ruby on the market? > -> I need to have the architectural UML Overview!! > (How do all the gbig ruby projects do this??) Not that I'm aware of. But I'd be curious to learn. Please let us know if you find something like this. > 6. I am missing the java toString method in Ruby. > -> Isn't there an easy way to define an objects puts behaviour? I'm surprised that you missed that one. :-) Btw, what is your project about? Kind regards robert