Class: DefinePoro::As

Inherits:
Object
  • Object
show all
Defined in:
lib/define-poro/as.rb

Class Method Summary collapse

Class Method Details

.new(*attributes, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/define-poro/as.rb', line 3

def self.new(*attributes, &block)
  Class.new do
    class_eval(%(
      attr_reader #{attributes.map { |a| ":#{a}" }.join(', ')}

      def initialize(#{attributes.join(', ')})
        #{attributes.map { |a| "@#{a}=#{a}" }.join('; ')}
      end
    ))

    class_exec &block if block_given?
  end
end