Sha256: 70e85ba8f95e9e727e1483ef2e0d2deb33c5ad74c7b51e6c5a24d6af2f955c68
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 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}(&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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
resourcelogic-0.9.0 | lib/resourcelogic/accessors.rb |