trouble with subobjects tree in FXRuby

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é
 
T

ts

Try this

A> def show()


def show
instance_variables.each do |iv|
p instance_variable_get(iv)
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top