Skip to content

Instantly share code, notes, and snippets.

@carlosbrando
Created February 4, 2011 02:51
Show Gist options
  • Save carlosbrando/810666 to your computer and use it in GitHub Desktop.
Save carlosbrando/810666 to your computer and use it in GitHub Desktop.
Shared Scope
def define_methods
shared = 0
Kernel.send :define_method, :counter do
shared
end
Kernel.send :define_method, :inc do |x|
shared += x
end
end
define_methods
p counter
inc(4)
p counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment