Last active
September 16, 2016 08:57
-
-
Save TeWu/f9f285408ab5ee2dafdde53e11da3028 to your computer and use it in GitHub Desktop.
Refactor or not to refactor - that is the question: Whether 'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune. Or to take arms against a sea of troubles. And by opposing end them.
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
def prev_photo_url(album, photo, **options) | |
prev_photo_id = album.prev_photo_id(photo) | |
album_photo_url album, prev_photo_id, options if prev_photo_id | |
end | |
def prev_photo_path (album, photo, **options) | |
prev_photo_url(album, photo, {only_path: true}.merge!(options)) | |
end | |
def next_photo_url(album, photo, **options) | |
next_photo_id = album.next_photo_id(photo) | |
album_photo_url album, next_photo_id, options if next_photo_id | |
end | |
def next_photo_path (album, photo, **options) | |
next_photo_url(album, photo, {only_path: true}.merge!(options)) | |
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
[:path, :url].each do |variant| | |
define_method "prev_photo_#{variant}" do |album, photo, **options| | |
prev_photo_id = album.prev_photo_id(photo) | |
send("album_photo_#{variant}", album, prev_photo_id, options) if prev_photo_id | |
end | |
define_method "next_photo_#{variant}" do |album, photo, **options| | |
next_photo_id = album.next_photo_id(photo) | |
send("album_photo_#{variant}", album, next_photo_id, options) if next_photo_id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment