Created
May 5, 2015 08:02
-
-
Save jacobdam/184e99819841bcf903ce to your computer and use it in GitHub Desktop.
Lazy-lize class loading dependency
This file contains 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
# bad | |
class Book | |
belongs_to :categoy, :class_name => BookCategory | |
end | |
# good | |
class Book | |
belongs_to :categoy, :class_name => 'BookCategory' | |
end | |
# bad | |
class Institution | |
STRATEGY = SomeStrategy | |
def strategy | |
STRATEGY | |
end | |
end | |
# good | |
class Institution | |
STRATEGY = 'SomeStrategy' | |
def strategy | |
STRATEGY.constantize | |
end | |
end | |
# bad | |
class Book | |
scope :for_children, where(category_id: Category::CHILDRED_CATEGORY_IDS) | |
end | |
# good | |
class Book | |
scope :for_children, lambda { | |
where(category_id: Category::CHILDREN_CATEGORY_IDS) | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment