-
-
Save tubbo/4252730 to your computer and use it in GitHub Desktop.
Good idea?
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 Editor < ActiveRecord::Base | |
| belongs_to :user | |
| def do_editor_stuff;end | |
| end |
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
| writer = User.find(123) | |
| writer.do_writer_stuff() if writer.is_writer? | |
| editor = User.find(456) | |
| editor.do_editor_stuff() if editor.is_editor? |
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 User < ActiveRecord::Base | |
| has_one :writer | |
| has_one :editor | |
| delegate :do_writer_stuff, :writer | |
| delegate :do_editor_stuff, :editor | |
| def is_writer? | |
| self.writer.present? | |
| end | |
| def is_editor? | |
| self.editor.present? | |
| end | |
| end |
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 Writer < ActiveRecord::Base | |
| belongs_to :user | |
| def do_writer_stuff;end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment