Sha256: d2a90a175d9929f63070d30173d104f56fbaaf25cb7a1341d8b61204966cbf33
Contents?: true
Size: 1.63 KB
Versions: 20
Compression:
Stored size: 1.63 KB
Contents
module Resourcelogic # :nodoc: module Accessors # :nodoc: private def block_accessor(*accessors) accessors.each do |block_accessor| class_eval <<-"end_eval", __FILE__, __LINE__ def #{block_accessor}(*args, &block) unless args.empty? && block.nil? args.push block if block_given? @#{block_accessor} = [args].flatten end @#{block_accessor} end end_eval end end def scoping_reader(*accessor_names) accessor_names.each do |accessor_name| class_eval <<-"end_eval", __FILE__, __LINE__ def #{accessor_name}(&block) @#{accessor_name}.instance_eval &block if block_given? @#{accessor_name} end end_eval end end def class_scoping_reader(accessor_name, start_value) write_inheritable_attribute accessor_name, start_value class_eval <<-"end_eval", __FILE__, __LINE__ def self.#{accessor_name}(context = :root, &block) read_inheritable_attribute(:#{accessor_name}).instance_eval(&block) if block_given? read_inheritable_attribute(:#{accessor_name}) end end_eval end def reader_writer(accessor_name) class_eval <<-"end_eval", __FILE__, __LINE__ def #{accessor_name}(*args, &block) args << block unless block.nil? @#{accessor_name} = args.first unless args.empty? @#{accessor_name} end end_eval end end end
Version data entries
20 entries across 20 versions & 2 rubygems