Skip to content

Instantly share code, notes, and snippets.

@packrat386
Last active September 5, 2018 22:00
Show Gist options
  • Save packrat386/18ffc5f91fd42cb04c15397c23ec7469 to your computer and use it in GitHub Desktop.
Save packrat386/18ffc5f91fd42cb04c15397c23ec7469 to your computer and use it in GitHub Desktop.
def myfunc(prog = "")
mystr = "hi there"
eval(prog)
mystr.scream
end
puts 'first'
begin
myfunc
rescue => e
puts "got error #{e}"
end
puts '================'
puts 'second'
begin
myfunc('class String; def scream; $stdout.puts self.upcase; end; end;')
rescue => e
puts "got error #{e}"
end
class Screamer
def scream
puts 'AAAAAAH'
end
end
puts '================'
puts 'third'
begin
myfunc('mystr = Screamer.new')
rescue => e
puts "got error #{e}"
end
=begin
first
got error undefined method `scream' for "hi there":String
================
second
HI THERE
================
third
AAAAAAH
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment