Module: Buildr::Attributes
- Included in:
- Java::CompileTask::Options, Project
- Defined in:
- lib/core/core.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#inherited_attr(symbol, default = nil, &block) ⇒ Object
An inherited attribute gets it value from an instance variable with the same name.
Class Method Details
.included(mod) ⇒ Object
15 16 17 |
# File 'lib/core/core.rb', line 15 def self.included(mod) mod.extend(self) end |
Instance Method Details
#inherited_attr(symbol, default = nil, &block) ⇒ Object
An inherited attribute gets it value from an instance variable with the same name. If the value is not set it will defer to the parent object. If there is no parent object, it will use the default value; with a block, it evaluates the block by calling instance_eval on the object.
For example:
inherited_attr :version
inherited_attr :src_dir, "src"
inherited_attr :java_src_dir do src_dir + "/main/java"
29 30 31 32 33 34 35 36 37 |
# File 'lib/core/core.rb', line 29 def inherited_attr(symbol, default = nil, &block) block ||= proc { default } define_method symbol do instance_variable_get("@#{symbol}") || (parent ? parent.send(symbol) : self.instance_eval(&block)) end define_method "#{symbol}=" do |value| instance_variable_set("@#{symbol}", value) end end |