Last active
August 29, 2015 13:56
-
-
Save JoelHough/8855759 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
require 'continuation' | |
def with_caller_binding | |
cc = nil | |
count = 0 | |
set_trace_func lambda { |event, file, lineno, id, binding, klass| | |
if count == 2 | |
set_trace_func nil | |
cc.call yield(binding) | |
elsif event == "return" | |
count += 1 | |
end | |
} | |
return callcc { |cont| cc = cont } | |
end | |
class Object | |
def method_missing(sym, *args) | |
return unless args.first.respond_to?(:call) | |
with_caller_binding do |b| | |
args.first.call(eval("#{sym}", b)) | |
end | |
end | |
end | |
def ∈(list) | |
lambda {|x| list.include? x} | |
end | |
def oh_god_why | |
elem = :bar | |
list = [:foo, :baz, :bar] | |
elem ∈ list | |
end | |
puts oh_god_why |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment