Created
January 28, 2009 08:02
-
-
Save GertThiel/53862 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 UserSession | |
def viewable_posts | |
# By using Post.scoped({}) rather than Post.all, you get a named scope proxy back, | |
# meaning that you can chain other scopes onto it | |
# and that the query is not executed until necessary. | |
admin? ? Post.scoped({}) : Post.published | |
end | |
end | |
class User | |
def pastor? | |
roles.any? { |r| r.title.include?('Pastor') } | |
end | |
end | |
User.all.each do |user| | |
# do something with “user” | |
end | |
# Greedy vs. non-greedy reg exp | |
i = 'acdbcdb' | |
i.match(/a.+b/)[0] # greedy, yields “acdbcdb” | |
i.match(/a.+?b/)[0] # non-greedy, yields “acdb” |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment