多判断转发的方案

很多场景用到条件分发跳转

方案一:

def aa(condition,option)
if condition == 1
todo 1
elsif condition == 2
todo 2
end
end

[b]示例:[/b]

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

[b]示例:[/b]

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

[b]示例:[/b]

@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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值