码迷,mamicode.com
首页 > 其他好文 > 详细

ruby开发之hash遍历each_with_index

时间:2015-11-26 09:34:02      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

<div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"> #设置奖励信息</span></div>        def set_award_info(task_params,award_params)
          if task_params[:goods_id].to_i == Sequel::Model::TABLE
            # 更新sys_task_award_account
            award_params[:account].split(/;/).each do |params|
              task_award = {}
              task_award[:account_id] = nil
              task_award[:award_type] = nil
              task_award[:base_amount] = nil
              task_award[:min_amount] = nil
              task_award[:max_amount] = nil
              task_award[:award_equation] = nil

              params = params.split(/:/)
              task_award.each_with_index do |(key,value),index|
                task_award[key] = params[index]
              end
              task_award[:task_id] = task_params[:task_id]
              task_award[:create_time] = Time.now
              task_award[:update_time] = Time.now
              sys_task_award_account = CaiQiuService::CoreDao::SysTaskAwardAccount.new
              sys_task_award_account.save_hash(task_award)
            end

          end
          #其他类型 TODO
        end

ruby开发之hash遍历each_with_index

标签:

原文地址:http://blog.csdn.net/sinat_29843547/article/details/50045031

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!