A
Aki Wakabayashi
Hello.
Absolute newb here, and my very first post, so please bear with me...I
would like to be able to access an object with it's instance variable. I
simplified my example, but for instance:
class Foo
attr_accessor :some_id
end
one = Foo.new('7a')
two = Foo.new('2t')
three = Foo.new('33')
Is it possible to use the instance variable @some_id to access the
object itself? I was thinking of creating a class method for class Foo
such as:
class Foo
attr_accessor :some_id
self.find(some_id)
# somehow get an array of all the Foo objects, and iterate through
their
# some_id attributes until a match(s) is found, return the object(s)
end
end
...so I can do something like Foo.find('7a43') to access the object
'one'.
I am exhausted from searching how to get an array or hash of objects of
a given class, and I think I'm going in the wrong direction. Any
pointers will be greatly appreciated.
Thank you in advance
Absolute newb here, and my very first post, so please bear with me...I
would like to be able to access an object with it's instance variable. I
simplified my example, but for instance:
class Foo
attr_accessor :some_id
end
one = Foo.new('7a')
two = Foo.new('2t')
three = Foo.new('33')
Is it possible to use the instance variable @some_id to access the
object itself? I was thinking of creating a class method for class Foo
such as:
class Foo
attr_accessor :some_id
self.find(some_id)
# somehow get an array of all the Foo objects, and iterate through
their
# some_id attributes until a match(s) is found, return the object(s)
end
end
...so I can do something like Foo.find('7a43') to access the object
'one'.
I am exhausted from searching how to get an array or hash of objects of
a given class, and I think I'm going in the wrong direction. Any
pointers will be greatly appreciated.
Thank you in advance