Skip to content

Instantly share code, notes, and snippets.

@0x0dea
Created August 18, 2015 07:06
Show Gist options
  • Save 0x0dea/a6cac7a018475985a574 to your computer and use it in GitHub Desktop.
Save 0x0dea/a6cac7a018475985a574 to your computer and use it in GitHub Desktop.
class Context
def initialize
@magic = {}
@lines = IO.readlines(__FILE__)
end
def method_missing *args
@magic[@lines[caller_locations[0].lineno - 1][/\s*(\S+)\s*=/, 1]] = args
end
end
def Foo
ctx = Context.new
ctx.instance_eval(&proc)
p ctx.instance_variable_get(:@magic)
end
Foo do
foo = some :thing
bar = other 1, 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment