D
denize.paul
My intent is to create a class that has access to call a method in an
instantiation of another class
However my knowledge of Ruby classes (Ok classes in general) is
somewhat lacking
The example below is a LOT simplified But I need class B to call a
method within an instantiation of class A's.
one alternative is to seperate the classes and then just do "b=B.new
(a)" but I think that looks really messy and
- I have then to check a bunch of stuff about the parameter a
- I would have a world of more hurt trying to ensure that only one B
instantiation pointed to each a
Can anyone help? Or tell me that I am doing this all wrong.
Paul
-----
class A
class B
def initialize()
puts "b init"
print_stuff()
end
end
def B
return B
end
def print_stuff()
puts "here"
end
end
a = A.new()
b = a.B.new()
instantiation of another class
However my knowledge of Ruby classes (Ok classes in general) is
somewhat lacking
The example below is a LOT simplified But I need class B to call a
method within an instantiation of class A's.
one alternative is to seperate the classes and then just do "b=B.new
(a)" but I think that looks really messy and
- I have then to check a bunch of stuff about the parameter a
- I would have a world of more hurt trying to ensure that only one B
instantiation pointed to each a
Can anyone help? Or tell me that I am doing this all wrong.
Paul
-----
class A
class B
def initialize()
puts "b init"
print_stuff()
end
end
def B
return B
end
def print_stuff()
puts "here"
end
end
a = A.new()
b = a.B.new()