Created
January 17, 2013 12:58
-
-
Save leejarvis/4555789 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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