0

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?

4

2 回答 2

1

尝试:

class B
  class << self
    undef var=
  end
end

您可能想改用 remove_method :

class B
  class << self
    remove_method :var=
  end
end

要查看差异,请访问: http: //www.nach-vorne.de/2008/2/28/undef_method-remove_method/

于 2010-03-22T17:24:51.617 回答
0
class <<B ; remove_method :var= ; end
于 2010-03-22T17:20:27.280 回答