Sha256: c979e5108b97d5fda3635aaebff350da35351433062a4c5a63dbf6cbd369d872
Contents?: true
Size: 1.12 KB
Versions: 16
Compression:
Stored size: 1.12 KB
Contents
module ROM # Internal support module for class-level settings # # @private module ClassMacros # Specify what macros a class will use # # @example # class MyClass # extend ROM::ClassMacros # # defines :one, :two # # one 1 # two 2 # end # # class OtherClass < MyClass # two 'two' # end # # MyClass.one # => 1 # MyClass.two # => 2 # # OtherClass.one # => 1 # OtherClass.two # => 'two' # # @api private def defines(*args) mod = Module.new args.each do |name| mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name}(value = Undefined) if value == Undefined defined?(@#{name}) && @#{name} else @#{name} = value end end RUBY end delegates = args.map { |name| "klass.#{name}(#{name})" }.join("\n") mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1 def inherited(klass) super #{delegates} end RUBY extend(mod) end end end
Version data entries
16 entries across 16 versions & 2 rubygems