Skip to main content
added 26 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

Don't use a for-loop (each), that's how you'd do it in language like C, in Ruby we have handy functional abstractions (or can build them if not present) like Enumerable#any?:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end

Don't use a for-loop, that's how you'd do it in language like C, in Ruby we have abstractions (or can build them if not present) like Enumerable#any?:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end

Don't use a for-loop (each), that's how you'd do it in language like C, in Ruby we have handy functional abstractions (or can build them if not present) like Enumerable#any?:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end
deleted 162 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

I would like to know if there is any...

Exactly that is what you should checkDon't use a for-loop, that's how you'd do it in language like C, in Ruby we have abstractions (or can build them if there isnot present) like anyEnumerable#any? of the elements in the block which is true:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end

In Ruby (or any language with functional capabilities, for that matter) it's not idiomatic to use a imperative loop to do that.

I would like to know if there is any...

Exactly that is what you should check, if there is any of the elements in the block which is true:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end

In Ruby (or any language with functional capabilities, for that matter) it's not idiomatic to use a imperative loop to do that.

Don't use a for-loop, that's how you'd do it in language like C, in Ruby we have abstractions (or can build them if not present) like Enumerable#any?:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

I would like to know if there is any...

Exactly that is what you should check, if there is any of the elements in the block which is true:

receive_payment_on = config[:sections].any? do |section|
  if section[:applicants]
    section[:applicants][:sections].any? do |app_sec|
      app_sec[:employment] && app_sec[:employment][:receive_payment_on]
    end
  end
end

In Ruby (or any language with functional capabilities, for that matter) it's not idiomatic to use a imperative loop to do that.