Sha256: 788adbf2baa0bdfe5821aca8e3b798f52d12aa0b7da3e9ccc15eea2b6aaf1066

Contents?: true

Size: 919 Bytes

Versions: 35

Compression:

Stored size: 919 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}" }.join(', ')
    <<-EOS
require 'attributes_initializable'

class #{class_name}
  include AttributesInitializable
  attr_accessor_init #{tmp_fields}
end
    EOS
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.131 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.130 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.129 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.128 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.127 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.126 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.125 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.124 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.123 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.122 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.121 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.120 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.119 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.118 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.117 lib/eval_helper/attr_init_class_code.rb