Sha256: 3410c27a805978e4846f8eb897cd41e3e5a17c03c26f9d2c87f32f7970be76cb

Contents?: true

Size: 1.15 KB

Versions: 100

Compression:

Stored size: 1.15 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(hash[:if_cond], hash[:if_proc], hash[:else_proc])
  #       instance_eval code
  #     end
  #   end
  #
  #   hash = {
  #     input: "test",
  #     if_cond: "msg == 'test'",
  #     if_proc: "true",
  #     else_proc: "false",
  #   }
  #   EvalHelperTest.new.hoge(hash) # => return true
  #
  # else case
  #
  #   class EvalHelperTest
  #     include EvalHelper
  #
  #     def hoge(hash)
  #       msg = hash[:input]
  #       code = if_code(hash[:if_cond], hash[:if_proc], hash[:else_proc])
  #       instance_eval code
  #     end
  #   end
  #
  #   hash = {
  #     input: "not_test",
  #     if_cond: "msg == 'test'",
  #     if_proc: "true",
  #     else_proc: "false",
  #   }
  #   EvalHelperTest.new.hoge(hash) # => return false
  #
  def if_code(condition, if_proc, else_proc)
    <<-EOS
if #{condition}
  #{if_proc}
else
  #{else_proc}
end
    EOS
  end
end

Version data entries

100 entries across 100 versions & 1 rubygems

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