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.151 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.150 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.149 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.148 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.147 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.146 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.145 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.144 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.143 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.142 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.141 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.140 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.139 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.138 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.137 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.136 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.135 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.134 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.133 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.132 lib/eval_helper/attr_init_class_code.rb