Skip to content

Instantly share code, notes, and snippets.

@aedorn
Created December 21, 2012 18:07
Show Gist options
  • Save aedorn/4354609 to your computer and use it in GitHub Desktop.
Save aedorn/4354609 to your computer and use it in GitHub Desktop.
We want to get rid of having to set the @status variable all the time, and simply rely on the "some_test" method to return true or false to indicate whether it should remove the tags or not.
class SomeClass
def initialize
@id_control = IDControl.new
@status = false # instance variable we want to get rid of
end
def some_test
tags("CFG", "DSL") do
return false if some_other_test
return passing_test
end
end
def passing_test
@status = true
end
def tags *ids, &block
ids.each {|i| tag_id_add(i) }
yield
ensure
ids.each {|i| tag_id_remove(i) } if @status
@status = false
end
def tag_id_add id
@id_control.add id
end
def tag_id_remove id
@id_control.del id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment