Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created November 29, 2011 22:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoward/1406880 to your computer and use it in GitHub Desktop.
Save ahoward/1406880 to your computer and use it in GitHub Desktop.
proc > module
#! /usr/bin/env ruby
# ClassMethods/InstanceMethods as modules are nice. but procs are mo betta. you can't do any of the following via modules.
#
module M
ClassMethods = proc do
class << self
alias_method 'bar', 'foo'
end
alias_method 'bar', 'foo'
Const = 42
# has_one :record_will_work
# validates_format_of :something_will_work
end
InstanceMethods = proc do
end
def M.included(other)
super
other.send(:instance_eval, &ClassMethods)
other.send(:class_eval, &InstanceMethods)
end
end
class C
def C.foo() 42 end
def foo() 42 end
include M
end
p C::Const #=> 42
p C.foo() #=> 42
p C.bar() #=> 42
p C.new.foo() #=> 42
p C.new.bar() #=> 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment