Class: Dun::Land
- Inherits:
-
Object
- Object
- Dun::Land
- Defined in:
- lib/dun.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .<<(data = {}) ⇒ Object
- .data_reader(*attrs) ⇒ Object
- .default(attr, default_value) ⇒ Object
- .inherited(subclass) ⇒ Object
- .set(attr, value) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(data) ⇒ Land
constructor
A new instance of Land.
Constructor Details
#initialize(data) ⇒ Land
Returns a new instance of Land.
49 50 51 |
# File 'lib/dun.rb', line 49 def initialize data @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/dun.rb', line 3 def data @data end |
Class Method Details
.<<(data = {}) ⇒ Object
20 21 22 |
# File 'lib/dun.rb', line 20 def << data = {} new(data).call end |
.data_reader(*attrs) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dun.rb', line 24 def data_reader *attrs attrs.each do |attr| define_method attr do instance_variable_get("@#{attr}") ||\ instance_variable_set("@#{attr}", data[attr.to_sym] || data[attr.to_s]) end end end |
.default(attr, default_value) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/dun.rb', line 35 def default attr, default_value orig_attr = "#{attr}_without_default" alias_method orig_attr, attr define_method attr do send(orig_attr) || default_value end end |
.inherited(subclass) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/dun.rb', line 5 def self.inherited subclass return if Kernel.method_defined? subclass.name Kernel.class_eval %Q{ def #{subclass.name} data = {}, &p #{subclass.name}.new(data).call &p end } rescue SyntaxError, TypeError end |
.set(attr, value) ⇒ Object
43 44 45 |
# File 'lib/dun.rb', line 43 def set attr, value define_method(attr) {value} end |
Instance Method Details
#call ⇒ Object
53 54 55 |
# File 'lib/dun.rb', line 53 def call return self end |