Better practice to find the max/min element in a loop Is this the most elegant way to avoid declaring additional variables outside the       following_triggers loop?

      closest_trigger_utc_time = (2**(0.size * 8 -2) -1)
  following_triggers.each do |test|
    closest_trigger_utc_time = test.utc_time if test.utc_time &lt; closest_trigger_utc_time
  end
Enumerable has many useful methods that solve problems like this. In this case you want map and min or min_by:

closest_trigger_utc_time = following_triggers.map{|test| test.utc_time}.min


2**(0.size * 8 -2) -1 is a bad way to write infinity. If you must have an infinity value, use Float::INFINITY instead, but it's better to avoid this. min returns nil for empty input, so it's convenient to use that as the default value, or replace it with something else by closest_trigger_utc_time || some_meaningful_default.