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

Version Path
tbpgr_utils-0.0.96 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.95 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.94 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.93 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.92 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.91 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.90 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.89 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.88 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.87 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.86 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.85 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.84 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.83 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.82 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.81 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.80 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.79 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.78 lib/eval_helper/attr_init_class_code.rb
tbpgr_utils-0.0.77 lib/eval_helper/attr_init_class_code.rb