以下のrubyのコードについて、result1は出力できるのにresult2は出力できないのはなぜですか?

if result1 = 'hoge'
  puts "result1 is #{result1}"
end

puts "result2 is #{result2}" if result2 = 'hoge'

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
$ ruby sample.rb
sample.rb:1: warning: found = in conditional, should be ==
sample.rb:5: warning: found = in conditional, should be ==
result1 is hoge
Traceback (most recent call last):
sample.rb:5:in `<main>': undefined local variable or method `result2' for main:Object (NameError)
Did you mean?  result1