Class: Abstract::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/abstracts.rb

Overview

Abstract::Builder class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Abstract::Builder

Define attribute writers to Abstract::Builder instance according to

existing accessors of Abstract::Object instance

Parameters:

  • object (String)
    • Abstract::Object.class.name



49
50
51
52
53
54
55
56
# File 'lib/abstracts.rb', line 49

def initialize(object)
  @object = Class.const_get(object).new
  @object.attrs.each do |attr|
    define_singleton_method "#{attr}=" do |param|
      @object.public_send("#{attr}=", param)
    end
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



35
36
37
# File 'lib/abstracts.rb', line 35

def object
  @object
end

Class Method Details

.build {|builder| ... } ⇒ Object

Create an instance of Abstract::Object class and yield block to it

Yields:

  • (builder)


39
40
41
42
43
# File 'lib/abstracts.rb', line 39

def self.build
  builder = new(@build_class)
  yield builder if block_given?
  builder.object
end