Skip to content

Instantly share code, notes, and snippets.

@allomov
Created March 29, 2011 20:53
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 allomov/893259 to your computer and use it in GitHub Desktop.
Save allomov/893259 to your computer and use it in GitHub Desktop.
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