Skip to content

Instantly share code, notes, and snippets.

@bachue
Created March 27, 2013 15:08
Show Gist options
  • Select an option

  • Save bachue/5254943 to your computer and use it in GitHub Desktop.

Select an option

Save bachue/5254943 to your computer and use it in GitHub Desktop.
class A
def f() 'A#f' end
end
module M
def f() 'M#f' end
def g() 'M#g' end
def k() 'M#k' end
end
a = A.new
class << a
include M
end
puts a.f # => A#f
puts a.g # => M#g
puts a.k # => M#k
class A
remove_method :f
end
puts a.f # => M#f
puts a.g # => M#g
puts a.k # => M#k
class A
def f() 'A#f' end
end
module M
def f() 'M#f' end
def g() 'M#g' end
def k() 'M#k' end
end
a = A.new
class << a
include M
end
puts a.f # => A#f
puts a.g # => M#g
puts a.k # => M#k
class << a
undef :f
end
puts a.f # => undefined method `f'
puts a.g # => 'M#g'
puts a.k # => 'M#k'
class A
def f() 'A#f' end
end
module M
def f() 'M#f' end
def g() 'M#g' end
def k() 'M#k' end
end
a = A.new
class << a
include M
end
puts a.f # => A#f
puts a.g # => M#g
puts a.k # => M#k
module M
undef :f
end
puts a.f # => undefined method `f'
puts a.g # => 'M#g'
puts a.k # => 'M#k'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment