Sha256: fe00317089bdafd1123628f8ab8260b3788fcdf480b05f6489fa6044dba8daf4

Contents?: true

Size: 1.14 KB

Versions: 97

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8

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

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.71 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.70 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.69 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.68 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.67 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.66 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.65 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.64 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.63 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.62 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.61 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.60 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.59 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.58 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.57 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.56 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.55 lib/eval_helper/unless_code_after.rb