I've never processed symbols before.  If I have an object and a symbol of an
instance variable, do I have to use eval to access the value, or is there a
faster way?

def printSide obj, side
	puts eval("obj."+side.id2name)
end
printSide(node,:left)

If I have to use eval, then why send a symbol at all?  Why not just send a
string?  Why does ruby even have Symbols?

-----Original Message-----
From: Robert Feldt [mailto:feldt / ce.chalmers.se]
Sent: Thursday, November 29, 2001 5:07 AM
To: ruby-talk ML
Subject: [ruby-talk:26887] Re: Can this be factored?


On Thu, 29 Nov 2001, Mark Hahn wrote:

> The two if statements below are identical except the words left and right
> (and < & >) are reversed.  I don't think this can be factored but I
thought
> I'd throw this out to see if anyone can think of a way.
>
I haven't gone through it all but what about the "pattern"

  a < b      => a.send(:<, b)

so that you can specify the method (:< or :>) in a parameter. Likewise for
@left or @right and off you go?!

/Robert