Sha256: 1ee30a8c5cd65fef722d95e082bf80f8c2c8d79250510b4d11817359e4312e31
Contents?: true
Size: 847 Bytes
Versions: 11
Compression:
Stored size: 847 Bytes
Contents
module Xot module UniversalAccessor def universal_accessor(*names, **names_with_options) names.each {|name| define_universal_accessor name} names_with_options.each {|name, opts| define_universal_accessor name, opts} end private def define_universal_accessor(name, options = {}) set = "ua_set_#{name}__" get = "ua_get_#{name}__" class_eval <<-END alias_method :#{set}, options[:writer] || :#{name}= alias_method :#{get}, options[:reader] || :#{name} private :#{set}, :#{get} def #{name}(*args, **kwargs) #{set}(*args, **kwargs) unless args.empty? && args.empty? #{get} end END end end# UniversalAccessor end# Xot class Module include Xot::UniversalAccessor end# Module
Version data entries
11 entries across 11 versions & 1 rubygems