Ruby. A problem with composition.
Posted: Sat Jun 27, 2015 8:59 pm
Is it possible to make this without going A class outside?
Because when I trying to run the second one it's won't work:
Because when I trying to run the second one it's won't work:
Code: Select all
class A
def initialize
@a = 0
end
def event_stuff
@a += 1
end
def get_a
@a
end
end
class RubyEdit
def init
@a = A.new
end
def event
@a.event_stuff
watch @a.get_a
end
end
#########################
class A
def initialize
@a = 0
end
def event_stuff
@a += 1
end
def get_a
@a
end
end
class B
def initialize
@a = A.new
end
def get_a
@a
end
def watch_a
@a.get_a
end
end
class RubyEdit
def init
@a = B.new
end
def event
@a.get_a.get_a
watch @a.watch_a
end
end