Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created December 9, 2012 20:40
Show Gist options
  • Save leejarvis/4246887 to your computer and use it in GitHub Desktop.
Save leejarvis/4246887 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
class Foo
include MethodFromClass
def initialize(name)
p name
end
end
Foo.new 'lee' #=> 'lee'
Foo 'lee' #=> 'lee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment