多判断转发的方案
程序员文章站
2022-07-14 18:52:40
...
很多场景用到条件分发跳转
方案一:
示例:
方案二:
示例:
方案三:
方案四:
示例:
方案一:
def aa(condition,option) if condition == 1 todo 1 elsif condition == 2 todo 2 end end
示例:
def get_charge(serve) if serve.is_a? QuantityServe charge = serve.compute_price(good.unified_quantity * number, extra) elsif serve.is_a? NumberServe charge = serve.compute_price(number, extra) else charge = serve.compute_price(number, extra) end charge end
方案二:
def bb(condition_x,option) send(condition_x,option) end def condition_1(option) end def condition_2(option) end
示例:
def perform(order_detail_id,action_tag,send_email,current_employee_name) Api::OverseasRealOrder.new(order_detail_id,send_email,current_employee_name).send(action_tag) end
方案三:
def cc(obj,option) obj = obj || obj.class obj.cc(option) end class a def cc(option) end end class b def self.cc(option) end end
方案四:
class base def initialize(objs,option) @objs @option end def a objs...option end end
示例:
@checked_items = CartItem.where(session_id: session_id).pending.checked SummaryService.new(@checked_items, buyer_id: buyer_id, extra: extra) class SummaryService def initialize(_checked_items, buyer_id: nil, extra: {}) @checked_items = _checked_items @buyer = Buyer.find(buyer_id) if buyer_id @extra = extra a b end def a end def b end end
推荐阅读
-
裂变营销新方案(一个小动作可以让你的粉丝帮你转发100+)
-
Linux系统下多版本php共存的解决方案(超简单)
-
Bootstrap modal 多弹窗之叠加显示不出弹窗问题的解决方案
-
CentOS下与Apache连接的PHP多版本共存方案实现详解
-
WINDOWS服务器安装多套PHP的另类解决方案
-
flex 多 State(场景)下组件不能访问的解决方案
-
IOS中判断卡顿的方案总结
-
利用js判断手机是否安装某个app的多种方案
-
基于kryo序列化方案的memcached-session-manager多memcached节点配置 memcachedwicketWebCSS
-
js判断开始时间与结束时间不大于24小时的解决方案