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

Ruby constants

For general discussion related FlowStone

Re: Ruby constants

Postby MyCo » Fri Feb 08, 2013 9:32 am

I know what self is, this wasn't the question. The question is, why you define a method explicitly with self (which makes it static).
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Ruby constants

Postby trogluddite » Fri Feb 08, 2013 10:22 am

MyCo wrote:Is it safe to assume, that all RubyEdits are initialized, before they receive external Inputs from other components

I'd want to test some more, but it certainly seems that way - what appears to happen is..
- 'init' run for all RubyEdits
- triggers from any 'output' methods in init get buffered.
- Green starts, and acts on the buffered triggers
- 'event' methods of Rubies act on the triggered data as usual.
I've not yet been able to trip this up by copy/pasting to change the startup order - but, as with you, I have only tried it so far on small schematics with only a few Ruby editors.

MyCo wrote:For the constants problem? From the documentation it looks like this should lock the variable. But in FS, when I try it, I still can change the value. Don't know what's going on there

Yes it's not what I expected either - but it is consistent with Ruby.
Variables are just pointers to objects - so the freeze command doesn't lock the variable, it locks the object to which the variable is pointing. So you can then no longer modify the object by calling its methods - but you can make the variable point to a different object entirely., because the '=' is an assignment, not a method call with the object as its receiver.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby constants

Postby MyCo » Fri Feb 08, 2013 8:16 pm

I've played around, and it doesn't work in bigger schematics. Looks like the trigger in this case is sent out before other elements are initialized. When the elements get initialized later, they don't even get the last value from the input, instead they used the values that were stored when the schematic was saved.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Ruby constants

Postby trogluddite » Fri Feb 08, 2013 10:26 pm

MyCo wrote:I've played around, and it doesn't work in bigger schematics

Dammit - I thought it was a bit too good to be true. :(

The only workaround I can see is to use an external trigger (After Load prim' ?) to trigger the value send - or maybe schedule a Ruby event from init to trigger it. But then, of course, you've got to make sure that nothing else reads it before that happens (or at least tests for that case and can handle the exception).
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby constants

Postby MyCo » Fri Feb 08, 2013 10:41 pm

I've already tried the "After Load" that you mentioned. This actually works, but in other RubyEdits you have to make sure, that the callback object is valid. Because there could be other triggered events before the Ruby Callbacks initial "After Load" comes in. Therefor I use "begin... rescue...end".
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Ruby constants

Postby trogluddite » Fri Feb 08, 2013 11:16 pm

MyCo wrote:Callbacks initial "After Load" comes in. Therefor I use "begin... rescue...end".

Yes, I'm starting to feel the need to look into that too - had a few times where resolving execution order was a lot harder than I though it would be.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby constants

Postby digitalwhitebyte » Fri Feb 08, 2013 11:29 pm

MyCo wrote:I know what self is, this wasn't the question. The question is, why you define a method explicitly with self (which makes it static).


def self.Const
1
end

If you send any message to self (e.g., self.Const) it is calling the Const method of your class.
Const= is just a setter method. If you want Const to be a variable, you must not use self.
User avatar
digitalwhitebyte
 
Posts: 106
Joined: Sat Jul 31, 2010 10:20 am

Re: Ruby constants

Postby MyCo » Sat Feb 09, 2013 12:00 am

As far as I understand it, if you define a method with self, you get a static class method. And actually, you don't need static methods in FS Ruby, unless you want to create multiple instances of a class... which you can't do with RubyEdit.

Here is what I mean:
Code: Select all
class Test
   def self.Const
      1
   end
   
   def Const
      2
   end
end

watch "static", Test.Const         # outputs 1
watch "instance", Test.new.Const   # outputs 2
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Ruby constants

Postby MyCo » Sat Feb 09, 2013 1:12 am

Another Ruby question:
Why does the ruby interpreter completely locks up, when you just type:
Code: Select all
redo


is there an outer loop, that we can't see?
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Ruby constants

Postby digitalwhitebyte » Sat Feb 09, 2013 3:44 am

Ruby redo Statement:
Syntax: redo
Restarts this iteration of the most internal loop, without checking loop condition.
Restarts yield or call if called within a block.
User avatar
digitalwhitebyte
 
Posts: 106
Joined: Sat Jul 31, 2010 10:20 am

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 122 guests