From: Ross Bamford Date: 2005-11-27T05:12:28+09:00 Subject: Re: Nubish questions about syntax and gems On Sat, 26 Nov 2005 16:14:24 -0000, daz wrote: > > 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 > Cheers :) I was missing quite a bit there... >> >> 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 > Definitely agree, I prefer to keep as much immutable as possible (too many years of Java I guess :P). I just thought there might be a convenient way to do setters, and keep the Rdoc [RW] or whatever identifiers correct at the same time. > >> >> 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 > Thanks for your reply :) -- Ross Bamford - rosco@roscopeco.remove.co.uk