Just an idea regarding frozen objects: this and other myriad situations could
be handled by object "states." That is, when in a certain "state", only
certain methods are available to an object, and those methods can be aliased.
When state changes, the methods swap out. For example, and this is just
pseudocode, mind you (I am making up some syntax that doesn't really exist):
class MyClass
def initialize
state[:on] = false
end
def on_true
return "TRUE"
end
def on_false
return "FALSE"
end
alias :on :on_false
state :on, :state => :on_state
end
m = MyClass.new
p m.on => "FALSE"
m.state[:on] = true
p m.on => "TRUE"
The way a frozen state could be implemented (aside from how it already is,
this is just a from-scratch idea) would be through states. Whenever an
object state changes, it would first restore the last state it was in, so you
could have a class like this:
class MyClass
def initialize
state[:frozen] = false
@var = nil
end
def var
@var
end
def var=(value)
@var = value
end
state :frozen, :var= => nil
end
m = MyClass.new
p m.var => nil
m.var = "SOMEVALUE"
p m.var => "SOMEVALUE"
m.state[:frozen] = true
m.var = "ANOTHERVALUE" => no such method error
Sean O'Dell