Page 1 of 1

ruby variables in own class

Posted: Mon Jan 13, 2014 12:41 am
by stw
Since i went into the challenge of trying to deal with ruby i run into several problems here and there.
Most have to do with real understanding of all that object relating stuff and doing the right things at the right place concerning this matter.
Anyway...i'd like to do something like that:

capture.jpg
capture.jpg (38.28 KiB) Viewed 13750 times

Whatever i tried so far (and it was a lot) i always get that nil error. AFAIK the prob is that the input doesn't get through to the class method? What do i have to do? I guess it's a simple question but i don't get it... :roll:

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 10:18 am
by stw
Nevermind... i got it. Must have done something wrong before but now it works with class variables. Constant works as well...

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 1:36 pm
by tester
As far I remember, there might be something with copy/paste order and parrent folders (modules) for classes.

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 2:04 pm
by chackl
This may not be a problem with the paste-Order

Defining a Class in a Rubyedit is OK - But getting data from the rubyEdit with the classdefinition is not OK and not that easy ... OK ...

Some smart guy told me some time ago "in ruby everything is an Object" :D (THX trogluddite) - well and if you think about that and combine this with global variables ($varname) then you have some power to get it working ;)

An example in in the file below

Kind Regards, C.Hackl

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 3:31 pm
by stw
Yes, that's how i did it. Thanks for your help. And as i mentioned it also works with class variables and constants. It doesn't necessarily have to ba a global var.

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 3:34 pm
by chackl
Maybe you could post a short example?

I know that i do not have the best solution :D - but maybe we could find a better :D

Re: ruby variables in own class

Posted: Mon Jan 13, 2014 3:47 pm
by stw
like this...

vartest.fsm
(464 Bytes) Downloaded 903 times