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.91 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.90 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.89 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.88 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.87 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.86 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.85 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.84 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.83 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.82 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.81 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.80 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.79 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.78 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.77 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.76 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.75 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.74 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.73 lib/eval_helper/unless_code_after.rb
tbpgr_utils-0.0.72 lib/eval_helper/unless_code_after.rb