Created
September 2, 2020 04:30
-
-
Save the-spectator/54785e2895fd4f34fba3d93af84b7fa6 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
# Example 1: Solution | |
# Assuming Address is polymorphic, filtering results by addressable_type = 'User' will only | |
# give result for user addresses. #present? returns false for nil & "" (empty string) hence | |
# filtering with not condition. | |
def get_addresses | |
Address.where(addressable_type: 'User'). | |
where.not(city: [nil, ""]). | |
to_a | |
end | |
# Example 2: Solution | |
class Greeting | |
attr_accessor :name | |
end | |
# Example 3: Solution | |
def sum(*operands) | |
operands.sum | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment