G
Greg Willits
If I need to dynamically reference instance vars, is this the only way
to do it (var set example)?
my_object.sendinstance_variable_set, "@#{iname}", ivalue)
I expected something more elegant, but this is the only way I can get it
to work. No biggie, just curious.
More complete example below.
-- gw
class Shape
attr_accessor :size, :fill_color, :line_color, :line_width
def initialize
@size = ""
@fill_color = ""
@line_color = ""
@line_width = ""
end
end
my_shape = Shape.new
shape_details = {
:size => 'small',
:fill_color => 'red',
:line_color => 'black',
:line_width => '2'}
shape_details.each do |iname, ivalue|
my_shape.sendinstance_variable_set, "@#{iname}", ivalue)
end
to do it (var set example)?
my_object.sendinstance_variable_set, "@#{iname}", ivalue)
I expected something more elegant, but this is the only way I can get it
to work. No biggie, just curious.
More complete example below.
-- gw
class Shape
attr_accessor :size, :fill_color, :line_color, :line_width
def initialize
@size = ""
@fill_color = ""
@line_color = ""
@line_width = ""
end
end
my_shape = Shape.new
shape_details = {
:size => 'small',
:fill_color => 'red',
:line_color => 'black',
:line_width => '2'}
shape_details.each do |iname, ivalue|
my_shape.sendinstance_variable_set, "@#{iname}", ivalue)
end