Sha256: 42d846fd830a3f70c7290d0067f2dd3771f3da7b571ca3afc56e63635ca3278b
Contents?: true
Size: 924 Bytes
Versions: 41
Compression:
Stored size: 924 Bytes
Contents
# encoding: utf-8 module EvalHelper # create attr_accessor + initialize code, for eval # # ==== Examples # # class EvalHelperAttrInitTest # include EvalHelper # # def hoge(hash) # attr_init_class_code(hash[:class_name], hash[:fields]) # end # end # # hash = { # class_name: "Hoge", # fields: [:hoge1, :hoge2, :hoge3], # } # EvalHelperAttrInitTest.new.hoge(hash) # # result # # require 'attributes_initializable' # # class Hoge # include AttributesInitializable # attr_accessor_init :hoge1, :hoge2, :hoge3 # end # def attr_init_class_code(class_name, fields) tmp_fields = fields.map { |v|":#{v.to_s}" }.join(', ') <<-EOS require 'attributes_initializable' class #{class_name} include AttributesInitializable attr_accessor_init #{tmp_fields} end EOS end end
Version data entries
41 entries across 41 versions & 1 rubygems