Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created March 10, 2011 22:11
Show Gist options
  • Select an option

  • Save ashmoran/865038 to your computer and use it in GitHub Desktop.

Select an option

Save ashmoran/865038 to your computer and use it in GitHub Desktop.
Example of overriding a method on a Class that is looked up dynamically from an instance
class Foo
class << self
def bar
"Foo.bar"
end
end
def bar
self.class.bar
end
end
class Baz < Foo
class << self
def bar
"Baz.bar"
end
end
end
describe "An object using a class method" do
subject { Foo.new }
its(:bar) { should eq "Foo.bar" }
end
describe "A subclass object using a class method" do
subject { Baz.new }
its(:bar) { should eq "Baz.bar" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment