If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Ruby. A problem with composition.
3 posts
• Page 1 of 1
Ruby. A problem with composition.
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
I hope my english was understeandable.
Skype id - parkidesu
Skype id - parkidesu
-
Parki - Posts: 20
- Joined: Fri Feb 27, 2015 11:12 am
Re: Ruby. A problem with composition.
not sure if I understand correctly, but I think the problem in the second code is here:
- Code: Select all
class RubyEdit
def init
@a = B.new
end
def event
@a.get_a.get_a # <<--- "get_a", not "event_stuff" ?
watch @a.watch_a
end
end
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Ruby. A problem with composition.
Like Maik said, if you are wondering why the second one doesn't count up, it's because "event_stuff" isn't called. Otherwise, you should provide an example of what you're trying to achieve.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 59 guests