Ruby - How to remove a setter on an object

Posted by Markus Orrelly on Stack Overflow See other posts from Stack Overflow or by Markus Orrelly
Published on 2010-03-22T17:05:39Z Indexed on 2010/03/22 17:21 UTC
Read the original article Hit count: 312

Given a class like this:

class B
    class << self
        attr_accessor :var
    end
end

Suppose I can't modify the original source code of class B. How might I go about removing the setter on the class variable var? I've tried using something like B.send("unset_method", "var="), but that doesn't work (nor does remove_method, or overwriting that method with a var= method that doesn't do anything). Any ideas?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about metaprogramming