O
Oliver Cromm
Can't find that discussed anywhere, but maybe I just don't know how to
look.
I have lots of style parameters in an object. First, I implemented it as
a hash, so I have the method
def set_style(stylepars)
stylepars.each {|key, val| @style[key] = val}
end
Now I want to exchange the Hash for an OpenStruct, because it's much
easier on the eyes in statements like this:
sepline = @style['verticalsep'] + sepline +
@style['horizontalsep']*@style['padding'] +
@style['verticalsep'] if @style['box']
But how can I set "the attribute whose name is in the variable *key*"?
look.
I have lots of style parameters in an object. First, I implemented it as
a hash, so I have the method
def set_style(stylepars)
stylepars.each {|key, val| @style[key] = val}
end
Now I want to exchange the Hash for an OpenStruct, because it's much
easier on the eyes in statements like this:
sepline = @style['verticalsep'] + sepline +
@style['horizontalsep']*@style['padding'] +
@style['verticalsep'] if @style['box']
But how can I set "the attribute whose name is in the variable *key*"?