Sha256: 46555e413eb890d8884ae961c750168d7aea7ad28d869f6bbead13720dd20550
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
module PluginAWeek #:nodoc: module AttributePredicates module Module def self.included(base) #:nodoc: base.class_eval do [:attr, :attr_reader, :attr_writer, :attr_accessor].each do |method| alias_method_chain method, :predicates end end end def attr_with_predicates(*args) #:nodoc: attr_without_predicates(*args) attr_predicate(args.first) end [:attr_reader, :attr_writer, :attr_accessor].each do |method| define_method("#{method}_with_predicates") do |*symbols| send("#{method}_without_predicates", *symbols) symbols.each {|symbol| attr_predicate(symbol)} end end private # Returns true if the specified variable is not blank, otherwise false def attr_predicate(symbol) define_method("#{symbol}?") do !instance_variable_get("@#{symbol}").blank? end end end end end ::Module.class_eval do include PluginAWeek::AttributePredicates::Module end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attribute_predicates-0.1.0 | lib/attribute_predicates/extensions/module.rb |