On Fri, Jul 20, 2001 at 03:18:31AM +0900, Barnett, Aaron wrote:
> 
> i'd like to have a method that operates on an instance variable given its
> name...
> 
> class cat
> 	def initialize()
> 		@says = 'meow'
> 	end
> 
> 	def set(name, value)
> 		@<<name>> = value
> 	end
> end
> 
> cat.new().set('says', 'arf')
> 
> i figure it can be done but i cant find out how based on the documentation
> i've found.
> 
> thanks
>  aaron
> 

here ya go

class Cat
    def initialize
        @says = 'meow'
    end

    attr_accessor :says

    def set(name, value)
        self.send(name+"=", value)
    end
end

Cat.new.set('says','arf')

-- 

Doubt is a pain too lonely to know that faith is his twin brother.
- Kahlil Gibran