Is there any way of completely remove a class object’s methods
instead of
extending the class?I’d like to be able to do:
class A
attr :t
def initialize
@t = 1
end
enda = A.new
puts a.t # => 1Not extending… redefining here…
class A
attr :x
def initialize
@x = 3
end
enda = A.new
puts a.x # => 3
puts a.t # => error, instead of outputing nilI’m finding the above to be a major pain when debugging and
prototyping new
code in either irb or an embedded ruby, every time I reload a library.
You mean something like:
irb(main):001:0> class A
irb(main):002:1> attr :x
irb(main):003:1> def initialize
irb(main):004:2> @x = 3
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> a = A.new
=> #<A:0x2b31f28 @x=3>
irb(main):008:0> a.t
NoMethodError: undefined method `t’ for #<A:0x2b31f28 @x=3>
from (irb):8
irb(main):009:0> class A
irb(main):010:1> def method_missing(meth, *args)
irb(main):011:2> nil
irb(main):012:2> end
irb(main):013:1> end
=> nil
irb(main):014:0> a.t
=> nil