A
Andr?
Hi all,
I'm new to Ruby and I'm having a hard time trying to show the elements inside
a given object. I would appreciate a lot if someone could help me on that.
The code I'm stuck with is:
-----------------------------------------------------------
class Resource
def initialize(name,availabilityNum)
@name = name
@availabilityNum = availabilityNum
end
def to_s()
"name = " + name.to_s + " availabilityNum = " +availabilityNum.to_s
end
end
class Model
def initialize()
@array1 = [Resource.new("rms",10), Resource.new("joao",20)]
@array2 = [Resource.new("prfssrs",10), Resource.new("joao",20)]
end
def show()
self.instance_variables.each do |subObject|
subObjectInst = self.instance_eval {subObject}
subObjectInst.each {|arrayElement| p arrayElement }
end
end
end
model = Model.new
model.show
-----------------------------------------------------------
The result is => ["@array1", "@array2"]
What I expected to see was the contents of the arrays inside Model
Tanks,
André
I'm new to Ruby and I'm having a hard time trying to show the elements inside
a given object. I would appreciate a lot if someone could help me on that.
The code I'm stuck with is:
-----------------------------------------------------------
class Resource
def initialize(name,availabilityNum)
@name = name
@availabilityNum = availabilityNum
end
def to_s()
"name = " + name.to_s + " availabilityNum = " +availabilityNum.to_s
end
end
class Model
def initialize()
@array1 = [Resource.new("rms",10), Resource.new("joao",20)]
@array2 = [Resource.new("prfssrs",10), Resource.new("joao",20)]
end
def show()
self.instance_variables.each do |subObject|
subObjectInst = self.instance_eval {subObject}
subObjectInst.each {|arrayElement| p arrayElement }
end
end
end
model = Model.new
model.show
-----------------------------------------------------------
The result is => ["@array1", "@array2"]
What I expected to see was the contents of the arrays inside Model
Tanks,
André