Class: Class

Inherits:
Object show all
Defined in:
lib/safariwatir/core_ext.rb

Overview

Why shouldn’t this be in core Ruby?

Instance Method Summary collapse

Instance Method Details

#def_init(*attrs) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/safariwatir/core_ext.rb', line 3

def def_init(*attrs)
  constructor = %|def initialize(|
  constructor << attrs.map{|a| a.to_s }.join(",")
  constructor << ")\n"
  attrs.each do |attribute|
    constructor << "@#{attribute} = #{attribute}\n"
  end
  constructor << "end"
  class_eval(constructor)
end