Class: ShipMe::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Template

Returns a new instance of Template.



6
7
8
# File 'lib/ship_me/template.rb', line 6

def initialize(klass)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/ship_me/template.rb', line 3

def klass
  @klass
end

#options_blockObject

Returns the value of attribute options_block.



4
5
6
# File 'lib/ship_me/template.rb', line 4

def options_block
  @options_block
end

Instance Method Details

#make(attributes = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ship_me/template.rb', line 10

def make(attributes = {})
  proxy = Module.new
  attributes.each do |method, value|
    (class << proxy; self; end).send(:define_method, method) do
      value
    end
  end
  opts = proxy.instance_eval(&options_block)
  @klass.new(opts)
end