Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created January 17, 2013 12:58
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 leejarvis/4555789 to your computer and use it in GitHub Desktop.
Save leejarvis/4555789 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module MethodFromClass
def self.included(klass)
Object.send(:define_method, klass.to_s) do |*args|
klass.new(*args)
end
end
end
module Kernel
def new(klass)
klass
end
end
class Foo
include MethodFromClass
def initialize(name)
p name
end
end
Foo.new 'lee' #=> 'lee'
Foo 'lee' #=> 'lee'
new Foo('lee') #=> 'lee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment