For example
define_state(:foo) { ['joe', 'fred'] }
def add_friend(friend)
foo << friend
end
This does not work as foo << friend updates the array object, but there is no way to know that the foo state has been updated.
I have implemented a couple of solutions, and am interested in which people would prefer:
- define foo! method that will return an object that wrap the current value of foo, and observe any changes to that object. So you can write
def add_friend(friend)
foo! << friend
end
- define foo! method that simple does
foo = foo to indicate a state change. This would return self so that the methods could be chained
def add_friend(friend)
foo << friend; foo!
end
or
def add_friend(friend)
foo << friend
ensure
foo!.bar!
end
2b) In addition the Proc class can be updated so this works
lambda { |new_friend| foo << new_friend }.foo!
Just looking for people's input, preferences, or other ideas!
For example
This does not work as
foo << friendupdates the array object, but there is no way to know that the foo state has been updated.I have implemented a couple of solutions, and am interested in which people would prefer:
foo = footo indicate a state change. This would return self so that the methods could be chainedor
2b) In addition the Proc class can be updated so this works
Just looking for people's input, preferences, or other ideas!