Skip to content

Instantly share code, notes, and snippets.

@niklas
Created September 8, 2011 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklas/1203256 to your computer and use it in GitHub Desktop.
Save niklas/1203256 to your computer and use it in GitHub Desktop.
define Eigenclass method with closure
class Object
def eigenclass
class << self; self; end
end
def eigenclass_eval(&block)
eigenclass.instance_eval &block
end
end
me = "me"
def me.wine
STDERR.puts "*whining*"
end
thing = "dope"
me.eigenclass_eval do
define_method :enjoy do
STDERR.puts "ooh, #{thing}"
end
end
me.wine
me.enjoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment