Support

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

Problem with RubyEdit class inheritance.

For general discussion related FlowStone

Problem with RubyEdit class inheritance.

Postby Parki » Sun May 10, 2015 2:52 pm

How to make a class with ability to use Rubyedit class methods?
Attachments
Problem with RubyEdit class inheritance..jpg
Problem with RubyEdit class inheritance..jpg (33.82 KiB) Viewed 12828 times
I hope my english was understeandable.
Skype id - parkidesu
User avatar
Parki
 
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Re: Problem with RubyEdit class inheritance.

Postby KG_is_back » Sun May 10, 2015 7:58 pm

I was wondering the same thing... I think it is not possible. RubyEdit methods have very special meaning in a sense, that they interact with Flowstone via inputs and outputs of ruby components = they only have meaning in the context of RubyEdit instance. To make your class methods be able to use RubyEdit methods, you have to pass the RubyEdit object to them as an argument at some point.

See this example:
Code: Select all
class MyClass
   def myMethod(rubyedit)
   
   rubyedit.watch 1
   end
end

MyClass.new.myMethod(self)

"self" variable holds the current RubyEdit instance, and can be referenced inside MyClass, when passed as an argument.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Problem with RubyEdit class inheritance.

Postby MyCo » Sun May 10, 2015 8:39 pm

Ruby is one of the worst languages... there are always multiple ways to get things done, but none of them is easy to come up with.
Attachments
RubyEdit access (MyCo).fsm
(572 Bytes) Downloaded 850 times
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Problem with RubyEdit class inheritance.

Postby Parki » Wed May 13, 2015 5:18 pm

In not a normal way, but it works so thanks you guys,
but today I have some magic for you again.
How do I can get access to @ins array inside class I made?
I think it's gonna work with kind of a method like "get_ins" but where do I can get those methods?
-
By the way I'm I so stupid or it's okay to fuck with softwere when it does'n work?
I hope my english was understeandable.
Skype id - parkidesu
User avatar
Parki
 
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Re: Problem with RubyEdit class inheritance.

Postby Parki » Wed May 13, 2015 5:29 pm

ah I just got how to solve this, but in a shit code way.
does anyone knows the normal way?
I hope my english was understeandable.
Skype id - parkidesu
User avatar
Parki
 
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Re: Problem with RubyEdit class inheritance.

Postby KG_is_back » Wed May 13, 2015 6:13 pm

I think the problem is, you haven't developed the feeling for object-oriented language. In ruby everything is object or a method of an object.
Object basically holds a set of data. Methods are basically stuff you can use to modify/use that data. Class defines which data that particular the object type holds and what methods you can use on it. The point is, you can't access data of one object, from methods of another object. When you're cutting tomato, you can't use properties of an apple...

In ruby, when you use a method on an object, you pass different objects as parameters and the result is again an object, returned by the method.

@ins and @outs are arrays of objects. They are simply the data associated with RubyEdit object. Each RubyEdit object has its own set of @ins and @outs. Your custom class simply has no access to them, because they are part of RubyEdit. To make them available in your custom class / instance of that class, you have to pass them as parameters of a method of that class.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Problem with RubyEdit class inheritance.

Postby tulamide » Thu May 14, 2015 10:02 am

Additionly to KG's explanation, that I couldn't have done any better, you also disregard the scope of arguments/variables. A method's argument stays in the scope of the method's class.

In your top-left example, 'self' represents the method's class, which is 'RubyEdit'. In your bottom-left example, 'self' again represents the method's class, which this time is 'W'. In the top-right example 'self' is used from RubyEdit, so represents RubyEdit, and then given as argument to another class, overwriting the initial value of arg, so still represents RubyEdit.

It is essential to understand object orientation when using Ruby, because it is the most object oriented language currently. And scope is a very important aspect of object orientation.

To answer your question in the fourth example: Nothing.

EDIT: The post I am replying to was removed.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Problem with RubyEdit class inheritance.

Postby Parki » Thu May 14, 2015 1:54 pm

I found a mistake in the post so I just deleted it.
I hope my english was understeandable.
Skype id - parkidesu
User avatar
Parki
 
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am


Return to General

Who is online

Users browsing this forum: No registered users and 45 guests