From: daz Date: 2005-11-27T01:17:28+09:00 Subject: Re: Nubish questions about syntax and gems Ross Bamford wrote: > Hi folks. > > I'm getting on really well with Ruby (I've not enjoyed programming this > much for ages :)) but I've a few (probably simple) questions I'm hoping > you might be able to help with. > > 1) Is this the right way to define a method with a dynamic name? > http://www.outerbody.com/ruby/ri.do?class=Module&method=define_method > > 2) I'm struggling with boolean attributes, and question marks. > attr_accessor (etc) won't allow me to pass those names in (I guess because > they're illegal instance var names). I tried: > > attr_accessor :is_green > alias is_green? is_green > Suggest to stick with something like this: class Roo attr_accessor :colour def initialize @colour = :white end def is_green? @colour == :green end end r = Roo.new p r.is_green? #-> false r.colour = :green p r.is_green? #-> true > > 3) Does this > Awesome answer from Dr. Black ! > > 4) And finally, not exactly a Ruby question, but relevant here I hope? > With a RubyGem, [...] Pass on 4 ;) Hope someone else can help. daz