# Local and global variables in Ruby

mystrOutside = "I'm outside"
def fun1
   puts "Inside fun1:"
   mystr = "I'm local to f1"      # local 
   $mystrGlob = "I'm global"      # global
   puts "In #{__method__} mystr is defined as: #{defined?(mystr)}"
   if defined?(mystr)
      puts "In #{__method__} mystr is: #{mystr}"
   end
   puts "In #{__method__} $mystrGlob is defined as: #{defined?($mystrGlob)}"
   if defined?($mystrGlob)
      puts "In #{__method__} $mystrGlob is: #{$mystrGlob}"
   end
   puts "In #{__method__} mystrOutside is defined as: #{defined?(mystrOutside)}"
   if defined?(mystrOutside)
      puts "In #{__method__} mystrOutside is: #{mystrOutside}"
   end
   puts "\n"
end

fun1
puts "Outside:"
puts "Outside mystr is defined as: #{defined?(mystr)}"
if defined?(mystr)
   puts "Outside mystr is #{mystr}"
end
puts "Outside $mystrGlob is defined as: #{defined?($mystrGlob)}"
if defined?($mystrGlob)
   puts "Outside $mystrGlob is: #{$mystrGlob}"
end
puts "Outside mystrOutside is defined as: #{defined?(mystrOutside)}"
if defined?(mystrOutside)
   puts "Outside mystrOutside is: #{mystrOutside}"
end

