S
Shea Martin
Consider the following:
######################################################
#!ruby
class A
def initialize
@name = 'A'
end
end
class B < A
def initialize
super
@name = 'B'
@data = Array.new
end
def set_text( p_text )
@text = p_text
end
def B.from_a( p_A )
l_rslt = B.new
l_rslt.data = Array.new
end
private
def data=( p_new_array )
@data = p_new_array
end
end
a = A.new
b = B.from_a( a )
exit 0
#############################################################
My B.from_a does not compile, as 'data' is not a public member. My
quesiton is how can I keep restricted access to @data, but allow my
from_a method to work?
Or is there a better way to accomplish this? I don't want to have a
A.to_b method, as that introduces double coupling.
Thanks,
~S
######################################################
#!ruby
class A
def initialize
@name = 'A'
end
end
class B < A
def initialize
super
@name = 'B'
@data = Array.new
end
def set_text( p_text )
@text = p_text
end
def B.from_a( p_A )
l_rslt = B.new
l_rslt.data = Array.new
end
private
def data=( p_new_array )
@data = p_new_array
end
end
a = A.new
b = B.from_a( a )
exit 0
#############################################################
My B.from_a does not compile, as 'data' is not a public member. My
quesiton is how can I keep restricted access to @data, but allow my
from_a method to work?
Or is there a better way to accomplish this? I don't want to have a
A.to_b method, as that introduces double coupling.
Thanks,
~S