Problem with RubyEdit class inheritance.

For general discussion related FlowStone
Post Reply
User avatar
Parki
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Problem with RubyEdit class inheritance.

Post by Parki »

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 14563 times
I hope my english was understeandable.
Skype id - parkidesu
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Problem with RubyEdit class inheritance.

Post 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.
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Problem with RubyEdit class inheritance.

Post 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.
Attachments
RubyEdit access (MyCo).fsm
(572 Bytes) Downloaded 898 times
User avatar
Parki
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Re: Problem with RubyEdit class inheritance.

Post 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?
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.

Post by Parki »

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
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Problem with RubyEdit class inheritance.

Post 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.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Problem with RubyEdit class inheritance.

Post 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.
"There lies the dog buried" (German saying translated literally)
User avatar
Parki
Posts: 20
Joined: Fri Feb 27, 2015 11:12 am

Re: Problem with RubyEdit class inheritance.

Post by Parki »

I found a mistake in the post so I just deleted it.
I hope my english was understeandable.
Skype id - parkidesu
Post Reply