Remove_observer bug?
-
Hi,
I have found following strange behaviour:
I have one EntitiesObserver object and multiple definitions which are bound to the very same EntitiesObserver:
observer = MyEntitiesObserver.new Sketchup;;active_model.definitions.each do |definition| definition.entities.add_observer observer endand it works OK.
But when I try to remove observer from the entities I'm able to remove it only from the first definition in the list. Other definition.entities.remove_observer(observer) are giving me the 'false' result and entities are still being observed by this observer.
How do I properly unobserve multiple objects pointing to a single observer?
-
Is that code in a file that you are loading ?
The local reference
observerwill be invalid after the file is done loading. -
It's a pseudo-code. The actual code implies that observer object is a class instance variable:
class Scene attr_accessor(;observer) def initialize @observer = MyEntitiesObserver.new end def observe Sketchup;;active_model.definitions.each do |definition| definition.entities.add_observer @observer end end def unobservre Sketchup;;active_model.definitions.each do |definition| definition.entities.remove_observer @observer end end end
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement