Page 1 of 1
Problem with RubyEdit class inheritance.
Posted: Sun May 10, 2015 2:52 pm
by Parki
How to make a class with ability to use Rubyedit class methods?
Re: Problem with RubyEdit class inheritance.
Posted: Sun May 10, 2015 7:58 pm
by KG_is_back
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.
Re: Problem with RubyEdit class inheritance.
Posted: Sun May 10, 2015 8:39 pm
by MyCo
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.
Re: Problem with RubyEdit class inheritance.
Posted: Wed May 13, 2015 5:18 pm
by Parki
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?
Re: Problem with RubyEdit class inheritance.
Posted: Wed May 13, 2015 5:29 pm
by Parki
ah I just got how to solve this, but in a shit code way.
does anyone knows the normal way?
Re: Problem with RubyEdit class inheritance.
Posted: Wed May 13, 2015 6:13 pm
by KG_is_back
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.
Re: Problem with RubyEdit class inheritance.
Posted: Thu May 14, 2015 10:02 am
by tulamide
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.
Re: Problem with RubyEdit class inheritance.
Posted: Thu May 14, 2015 1:54 pm
by Parki
I found a mistake in the post so I just deleted it.