From: Hugh Sasse Date: 2008-11-04T03:10:36+09:00 Subject: Re: Text Based RPG in Ruby On Tue, 4 Nov 2008, Ruairidh Mchardy wrote: > Hi there Hugh, > > I'd previously taken a look at Dwemthy's array (Poignant Guide to Ruby > right) and it is undoubtedly a nice implementation of a text-based RPG > in Ruby. My problem is that I'm extremely stubborn and even lifting a > line of code makes me feel dirty. I know what you mean, but it is how progress is made. > > I want this program to be 100% written by me. I know that doesn't stop > me learning from others but I often end up writing code that is far too > similar for my liking! As long as you understand it, I'd say that's OK. But it's good to try other approaches as well. > > Also on a slightly embarassing note, my ruby skills are not to the level > where I can easily understand snippets such as: > > define_method( :initialize ) do > self.class.traits.each do |k,v| > instance_variable_set("@#{k}", v) > > or def self.metaclass; class << self; self; end; end > > def self.traits( *arr ) > return @traits if arr.empty? > > attr_accessor(*arr) > > arr.each do |a| > metaclass.instance_eval do > define_method( a ) do |val| > @traits ||= {} > @traits[a] = val > > And so my code is far less efficient and rather ugly too :( Exactly why I pointed you at the article about how to achieve this with modules, because I'm in much the same position. > > Thanks for the link though! > > Kind Regards, > > Ruairidh McHardy > Hugh