I made a User
class containing a class method find_by_email
:
class User
attr_accessor :email
def initialize
@email="[email protected]"
end
def self.find_by_email(pattern)
ObjectSpace.each_object(self) do |object|
puts object.email+" "+(object.email.include? pattern).to_s
end
end
end
In irb
I try:
irb> user1=User.new
irb> user2=User.new
irb> user1.email="[email protected]"
irb> User.find_by_email "s"
which returns:
[email protected] false
[email protected] true
I would like find_by_email
to return an array with the matching emails. So for this example it should only return ["[email protected]"]
. How can I refactor the find_by_email
class to achieve this?