require 'facet/kernel/nack' class Module # Create an tester attribute. This creates two methods for # each given variable name. One is used to test # the attribute and the other is used to set or toggle it. # # attr_switch :a # # is equivalent to # # def a? # @a ? true : @a # end # # def a!(switch=nack) # if switch == nack # @a = ! @a # else # @a = @a ? switch : @a # self # end # end # def attr_tester(*args) make = {} args.each { |a| make["#{a}?".to_sym] = %{ def #{a}?; @#{a} ? true : @#{a}; end } make["#{a}!".to_sym] = %{ def #{a}!(switch=nack) if switch==nack @#{a} = !@#{a} else @#{a} = @#{a} ? switch : @#{a} self end end } } module_eval make.values.join("\n") return make.keys end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # # TODO