Hi all,
I want to create an array of one of each class in ruby for testing purposes in pseudo-code I kind of want...
ObjectSpace.each_object(Class) do |c|
c.send(:new) # I want to instantiate here and store the resulting objects in an array
end
Ok so I can half do it, but I need to dynamically send the correct arguments for each objects initialize method - any good ideas?
Kev
7rans
(7rans)
2
You gogin to have trouble instatiating without know what it is. Try
#allocate:
objs = []
ObjectSpace.each_object(Class) do |c|
objs << c.allocate
end
p objs
T.
Robert
(Robert)
3
Trans wrote:
You gogin to have trouble instatiating without know what it is. Try
#allocate:
objs =
ObjectSpace.each_object(Class) do |c|
objs << c.allocate
end
p objs
There should at least be a rescue clause as not every class supports
#allocate:
ObjectSpace.each_object(Class) {|cl| cl.allocate}
TypeError: allocator undefined for Binding
from (irb):14:in `allocate'
from (irb):14
from (irb):14
Kind regards
robert