有没有办法在 Ruby 上缩短这条线?
if (res = bla_permission_invalid).is_a? String then return res end
上
def something # many things that like this
if (res = bla_permission_invalid).is_a? String then return res end
# do something else
return true
end
当 bla_permission_invalid 的内容类似于
def bla_permission_invalid
return invalid_address_report_func if invalid_address?
return permission_error_report_func if @user.not_one_of? [ :group1, :group2 ]
return nil
end
invalid_adress_report_func
并permission_error_report_func
返回字符串