B
Blake Miller
i'm trying to do this, and I'm stuck
class holderOfYs
def initialize()
@ys = Array.new
end
def addX( x )
@ys << x
end
# this is the problem function. all I want is the specific (ONE)
element
# from the @ys array that matches the id, but when you iterate over the
# array, i can't find a way to only have one element returned
def getXById(id)
@ys.each_with_index do |comp, index|
if( @ys[index].getUniqueId == id )
@ys.fetch(index)
end
end
end
class Y
@uniqueId
def getUniqueId
@uniqueId
end
end
class X < Y
def getUniqueId
super
end
end
I tried setting a variable like :
def getXById(id)
inst = X.new
@ys.each_with_index do |comp, index|
if( @ys[index].getUniqueId == id )
inst = @ys.fetch(index)
end
end
inst
end
...but I'm not looking to instantiate a new X, and even that solution
seems to screw up the @ys array.
class holderOfYs
def initialize()
@ys = Array.new
end
def addX( x )
@ys << x
end
# this is the problem function. all I want is the specific (ONE)
element
# from the @ys array that matches the id, but when you iterate over the
# array, i can't find a way to only have one element returned
def getXById(id)
@ys.each_with_index do |comp, index|
if( @ys[index].getUniqueId == id )
@ys.fetch(index)
end
end
end
class Y
@uniqueId
def getUniqueId
@uniqueId
end
end
class X < Y
def getUniqueId
super
end
end
I tried setting a variable like :
def getXById(id)
inst = X.new
@ys.each_with_index do |comp, index|
if( @ys[index].getUniqueId == id )
inst = @ys.fetch(index)
end
end
inst
end
...but I'm not looking to instantiate a new X, and even that solution
seems to screw up the @ys array.