Skip to content

Instantly share code, notes, and snippets.

@the-spectator
Created September 2, 2020 04:30
Show Gist options
  • Save the-spectator/54785e2895fd4f34fba3d93af84b7fa6 to your computer and use it in GitHub Desktop.
Save the-spectator/54785e2895fd4f34fba3d93af84b7fa6 to your computer and use it in GitHub Desktop.
# 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