public
Created

  • Download Gist
1st.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
module ExampleModule
def amethod
end
end
 
 
class AClass
end
 
apre_imethods = AClass.instance_methods
apre_smethods = AClass.singleton_methods
 
class AClass
include ExampleModule
extend ExampleModule
end
 
p AClass.instance_methods - apre_imethods
p AClass.singleton_methods - apre_smethods
 
class BClass
end
 
bpre_imethods = BClass.instance_methods
bpre_smethods = BClass.singleton_methods
 
class BClass
extend ExampleModule
include ExampleModule
end
 
p BClass.instance_methods - bpre_imethods
p BClass.singleton_methods - bpre_smethods
 
opre_imethods = Object.instance_methods
opre_smethods = Object.singleton_methods
 
class Object
include ExampleModule
extend ExampleModule
end
 
p Object.instance_methods - opre_imethods
p Object.singleton_methods - opre_smethods
2nd.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
module ExampleModule
def amethod
end
end
 
 
class AClass
end
 
apre_imethods = AClass.instance_methods
apre_smethods = AClass.singleton_methods
 
class AClass
include ExampleModule
extend ExampleModule
end
 
p AClass.instance_methods - apre_imethods
p AClass.singleton_methods - apre_smethods
 
class BClass
end
 
bpre_imethods = BClass.instance_methods
bpre_smethods = BClass.singleton_methods
 
class BClass
extend ExampleModule
include ExampleModule
end
 
p BClass.instance_methods - bpre_imethods
p BClass.singleton_methods - bpre_smethods
 
opre_imethods = Object.instance_methods
opre_smethods = Object.singleton_methods
 
class Object
extend ExampleModule
include ExampleModule
end
 
p Object.instance_methods - opre_imethods
p Object.singleton_methods - opre_smethods

~/Repositories ‹ruby-1.9.3› $ ruby exin.rb
[:amethod]
[:amethod]
[:amethod]
[:amethod]
[:amethod]
[:amethod]
~/Repositories ‹ruby-1.9.3› $ ruby inex.rb
[:amethod]
[:amethod]
[:amethod]
[:amethod]
[:amethod]
[]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.