Sha256: 37361b4e32780ddfcbf7b35495ae937171f6fc9673716c6b1fdfca81984a5ae7
Contents?: true
Size: 1014 Bytes
Versions: 1
Compression:
Stored size: 1014 Bytes
Contents
require 'nano/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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.9.0 | lib/nano/module/attr_tester.rb |