Sha256: 2b0c9fe13d1c946a7516a543503f33394d5d29993a7ae908dddcccc1d3c1e15f
Contents?: true
Size: 1015 Bytes
Versions: 2
Compression:
Stored size: 1015 Bytes
Contents
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}?"] = %{ def #{a}?; @#{a} ? true : @#{a}; end } make[:"#{a}!"] = %{ 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facets-1.0.0 | lib/facet/module/attr_tester.rb |
facets-1.0.3 | packages/core/lib/facet/module/attr_tester.rb |