`end`与一个或运算符

时间:2015-06-28 06:37:53

标签: ruby

我正在阅读这样的代码:

def majority_agreed_commit
  current_commit = log_container.last_commit

  current_term_match_indices = match_indices.values.map do |match_index|
    match_index.downto(current_commit).find do |i|
      log_container.term(i) == current_term
    end || current_commit
  end

我不明白这个含义:end || current_commit。有人能帮助我吗?

1 个答案:

答案 0 :(得分:4)

match_index.downto(current_commit).find do |i|
  log_container.term(i) == current_term
end

返回一个值,该值在逻辑上与current_commit相加,结果在最顶层map得出:

match_indices.values.map do |...|
  BLOCK_RESULT || current_commit
end