This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Thread.new do | |
begin | |
1/0 | |
rescue ZeroDivisionError => e | |
sleep 3 | |
end | |
end | |
Thread.pass while t.status and t.status != "sleep" | |
t.raise | |
p t.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class H | |
def hash | |
p "hash" | |
456 | |
end | |
end | |
h={} | |
p h[H.new] == nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1].each { eval "Const = 1" } | |
p Const | |
class Object | |
remove_const :Const | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a, b = Object.new, Object.new | |
result = nil | |
p a.instance_eval "x = 1" | |
lambda do | |
b.instance_eval "result = x" | |
end.call | |
p result == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Autoload | |
end | |
module Autoload | |
class W | |
autoload :Y, "/tmp/empty_file.rb" | |
class Y | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["/tmp/caller.rb:8", "/tmp/caller.rb:8"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
["(eval):1:in `<main>'", | |
"/tmp/caller.rb:5:in `eval'", | |
"/tmp/caller.rb:5:in `caller_of'", | |
"/tmp/caller.rb:9:in `<main>'"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
class Caller | |
def self.caller_of(block) | |
eval("caller(0)", block.binding) | |
end | |
end | |
block = lambda { 1 } | |
pp Caller.caller_of(block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rd, wr = IO.pipe | |
if Kernel::fork then | |
wr.close | |
p rd.read == "finalized" | |
rd.close | |
else | |
rd.close | |
obj = "Test" | |
handler = Proc.new { wr.write "finalized"; wr.close } | |
ObjectSpace.define_finalizer(obj, handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_syntax?(code, fname) | |
code.force_encoding("ascii-8bit") | |
code = code.sub(/\A(?:\s*\#.*$)*(\n)?/n) { | |
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n" | |
} | |
catch {|tag| eval(code, binding, fname, 0)} | |
end |