Created
December 21, 2012 18:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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