Created
December 30, 2009 01:12
-
-
Save perplexes/265774 to your computer and use it in GitHub Desktop.
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
class Object | |
# Yield ourself to the block given, and let the block determine the value to pass. | |
# This is like #tap, but "alter"s the output instead of ignoring it. | |
# Useful for conditional scoping, like: | |
# # For admins, show all posts. For others, show only public posts. | |
# @posts = Post.all.alter{|p| current_user.admin? ? p : p.public} | |
# | |
# Rather than: note the double assignment :( | |
# @posts = Post.all | |
# @posts = @posts.public unless current_user.admin? | |
def alter | |
yield self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment