Skip to content

Instantly share code, notes, and snippets.

@alindeman
Created January 12, 2011 14:02
Show Gist options
  • Select an option

  • Save alindeman/776188 to your computer and use it in GitHub Desktop.

Select an option

Save alindeman/776188 to your computer and use it in GitHub Desktop.
class Foo
def self.blah
"foo"
end
end
puts Foo.blah # "foo"
Foo.define_singleton_method :blah, do
"hijink"
end
puts Foo.blah # "hijink"
class Foo
def self.blah
"foo"
end
end
puts Foo.blah # "foo"
module FooExtend
def blah
"hijink"
end
end
Foo.singleton_class.send :extend, FooExtend
puts Foo.blah # "foo"
puts Foo.singleton_class.blah # "hijink"
class Foo
def self.blah
"foo"
end
end
puts Foo.blah # "foo"
singleton_class = class << Foo; self; end;
def singleton_class.blah
"hijink"
end
puts Foo.blah # "foo"
puts singleton_class.blah # "hijink"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment