From 0cd06fc1b9fcb21aacd006f4c7e2b7502131357c Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Sun, 8 Nov 2015 00:14:45 +0100 Subject: [PATCH] Propose Uber::InheritableAttr::DSL This allows thinks like: ```ruby class Base extend Uber::InheritableAttr::DSL inheritable_attr :from end class User < Base from 'nick@example.org' end ``` --- lib/uber/inheritable_attr/dsl.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/uber/inheritable_attr/dsl.rb diff --git a/lib/uber/inheritable_attr/dsl.rb b/lib/uber/inheritable_attr/dsl.rb new file mode 100644 index 0000000..461eabc --- /dev/null +++ b/lib/uber/inheritable_attr/dsl.rb @@ -0,0 +1,14 @@ +module Uber::InheritableAttr::DSL + include Uber::InheritableAttr + + def inheritable_attr(name, options={}) + super + instance_eval %Q{ + def #{name}(value = :__undefined) + return self.#{name} = value if value != :__undefined + return @#{name} if instance_variable_defined?(:@#{name}) + @#{name} = InheritableAttribute.inherit_for(self, :#{name}, #{options}) + end + } + end +end