Created
March 29, 2011 20:53
-
-
Save allomov/893259 to your computer and use it in GitHub Desktop.
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 Foo | |
def initialize(*args) | |
puts "Initializing Foo" | |
end | |
end | |
=> nil | |
def Foo(*args, &block) | |
puts args.inspect | |
block.call if block | |
Class.new(Foo).instance_eval <<-END | |
def initialize | |
# I'm going to do something with block and args here | |
puts "Double surprise!" | |
end | |
self | |
END | |
end | |
=> nil | |
class Bar < Foo("Hi there!") { | |
puts "Surprise!" | |
} | |
end | |
["Hi there!"] | |
Surprise! | |
=> nil | |
Bar.new | |
Initializing Foo | |
=> #<Bar:0x2f776b0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment