Sha256: 99e7522203b9f9bdf1c5f4ca83c3226a42b64534471642a720b28ea8a2bdcf81

Contents?: true

Size: 1.13 KB

Versions: 99

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module EvalHelper
  # create if strings, for eval
  #
  # ==== Examples
  #
  # if case
  #
  #   class EvalHelperTest
  #     include EvalHelper
  #
  #     def hoge(hash)
  #       msg = hash[:input]
  #       code = if_code_after(hash[:if_cond], hash[:if_proc])
  #       ret = 'dafault'
  #       instance_eval code
  #       ret
  #     end
  #   end
  #
  #   hash = {
  #     input: "test",
  #     if_cond: "msg == 'test'",
  #     if_proc: "ret = "true"",
  #   }
  #   EvalHelperTest.new.hoge(hash) # => return 'true'
  #
  # else case
  #
  #   class EvalHelperTest
  #     include EvalHelper
  #
  #     def hoge(hash)
  #       msg = hash[:input]
  #       code = if_code_after(hash[:if_cond], hash[:if_proc])
  #       ret = 'ret = "true"'
  #       instance_eval code
  #       ret
  #     end
  #   end
  #
  #   hash = {
  #     input: "not_test",
  #     if_cond: "msg == 'test'",
  #     if_proc: "ret = "true"",
  #   }
  #   EvalHelperTest.new.hoge(hash) # => return 'default'
  #
  def if_code_after(condition, if_proc)
    "#{if_proc} if #{condition}"
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.150 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.149 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.148 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.147 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.146 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.145 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.144 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.143 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.142 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.141 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.140 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.139 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.138 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.137 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.136 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.135 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.134 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.133 lib/eval_helper/if_code_after.rb
tbpgr_utils-0.0.132 lib/eval_helper/if_code_after.rb