Created
March 10, 2011 22:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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