Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Any of these should be runnable at the command line by `ruby <filename>`.
# check this out: http://www.nach-vorne.de/2007/3/18/list-of-callback-methods/
module M
def self.included(base)
puts "#{base.inspect} just included me!"
end
def self.extended(base)
puts "#{base.inspect} just got extended!"
end
end
class C
include M
end
class D
extend M
end
class C
end
module M
def hello
"I am from M"
end
end
module N
def hello
"I am from N"
end
end
C.send :include, M
puts C.new.hello
class C
include N
end
puts C.new.hello
module M
def hello
"I am from M"
end
end
module N
def hello
"I am from N"
end
end
class C
include M
alias :original_hello :hello
include N
end
puts C.new.methods.sort.inspect
puts C.new.respond_to? :original_hello
puts C.new.original_hello
puts C.new.hello
class C
def hello
"Hello from C"
end
end
module M
def hello
"Hello from M"
end
end
puts C.new.hello
C.send :include, M
puts C.new.hello
C.class_eval do
alias :old_hello :hello
include M
end
puts C.new.hello
C.class_eval do
def hello
"have some h8"
end
end
puts C.new.hello
# init.rb
ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods
# acts_as_archival_active_record_methods.rb
module ExpectedBehavior
module ActsAsArchivalActiveRecordMethods
def self.included(base)
base.extend ARClassMethods
base.send :include, ARInstanceMethods
end
module ARClassMethods
def is_archival?
self.included_modules.map(&:to_s).include?("ExpectedBehavior::ActsAsArchival::InstanceMethods")
end
end
module ARInstanceMethods
def is_archival?
self.class.is_archival?
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment