On 7-Dec-2005, at 9:23 PM, Steve Litt wrote:

> On Wednesday 07 December 2005 09:13 pm, Steve Litt wrote:
>> Hi all,
>>
>> I wrote some hierarchy handling classes in Node.rb
>> (http://www.troubleshooters.com/projects/Node.rb/index.htm), and  
>> I've been
>> told I write Ruby in Perl style. In future software, what could I  
>> do to
>> write in a more Ruby-like fashion?
>>
>> Thanks
>>
>> SteveT
>
> Whoops, the actual code is here:
> http://www.troubleshooters.com/projects/Node.rb/downloads/0.02/ 
> Node.rb, with
> test progarm here:
> http://www.troubleshooters.com/projects/Node.rb/downloads/0.02/ 
> testnode_parse.rb
> and test data here:
> http://www.troubleshooters.com/projects/Node.rb/downloads/0.02/ 
> test.otl

For:

def setAttributes(attribs) @attribs = attribs; end
def getAttributes() return @attribs; end
def hasAttributes() return @attribs != nil; end

You could use these (assuming you use @attributes as the instance  
variable in place of @attribs)

attr_accessor :attributes
def has_attributes?
   @attributes.empty?
end

and if you wanted to use a [] notation to access the attributes then  
you could say

def []=(key, val)
   @attributes[key] = v
end

def [](key)
   @attributes[key]
end

Hope this helps,

Mike (Perl refugee)


-- 

Mike Stok <mike / stok.co.uk>
http://www.stok.co.uk/~mike/

The "`Stok' disclaimers" apply.