Skip to content

Instantly share code, notes, and snippets.

@JoelHough
Last active August 29, 2015 13:56
Show Gist options
  • Save JoelHough/8855759 to your computer and use it in GitHub Desktop.
Save JoelHough/8855759 to your computer and use it in GitHub Desktop.
# -*- 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