Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created December 25, 2009 00:01
Show Gist options
  • Save yuheiomori/263429 to your computer and use it in GitHub Desktop.
Save yuheiomori/263429 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
module A
def self.included(base)
base.class_eval do
extend ClassMethods
test_class_method
end
end
module ClassMethods
def test_class_method
puts "called test_class_method:"
puts "self:"
p self
(class << self; self end).instance_eval do
define_method 'test_method' do |*args|
puts "called test_method"
end
end
end
end
end
class AA
include A
end
#クラスメソッドが定義される
AA.test_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment