Skip to content

Instantly share code, notes, and snippets.

@oem
Created February 19, 2011 07:59
Show Gist options
  • Save oem/834915 to your computer and use it in GitHub Desktop.
Save oem/834915 to your computer and use it in GitHub Desktop.
Use method_missing to dynamically create "faked" class methods
# method missing fun to fake class methods
class Foo
def tell(something)
puts something
puts yield
end
def self.method_missing(name, *args, &block)
if instance_methods.include? name
foo = Foo.new
foo.send(name, args, &block)
end
end
end
Foo.tell "moo" do
"moo"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment