Last active
September 9, 2016 13:43
-
-
Save JAMSUPREME/a45222cbebeb1549eb0a94357a6df4d6 to your computer and use it in GitHub Desktop.
Abstractions v2 stuff
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
# Example of a few bad things (not a comprehensive list of bad ideas) | |
class Event < ActiveRecord::Base | |
# Less OK - scopes and retrieval helpers | |
scope :expensive, -> { where('desired_fee > 1000') } | |
scope :more_expensive_than, ->(cost) { where('desired_fee > ?', cost) } | |
def jan_events | |
where("strftime('%m', tentative_date) = 01") | |
end | |
# Not OK - arcane code that probably isn't reusable | |
def do_weird_things(title, other_event, new_price, *args) | |
@title = title + args.join(' ? ') | |
other_event.title = @title | |
puts "#{new_price}" | |
end | |
# Not OK - view logic | |
def cool_title | |
"COOL #{@title}" | |
end | |
end |
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
# In our brilliance, we abstracted! | |
class Event < ActiveRecord::Base | |
include EventScopes | |
include EventWeirdThings | |
include EventHelpers | |
include StuffAndThings | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment