Created
September 8, 2011 12:15
-
-
Save niklas/1203256 to your computer and use it in GitHub Desktop.
define Eigenclass method with closure
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
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