Hi,

On 23/11/12 00:16, tamouse mailing lists wrote:
> On Thu, Nov 22, 2012 at 3:55 AM, Arlen Cuss<ar / len.me>  wrote:
>> If you don't mind them accessing all vars through a name, you could have an API like:
>>
>> class A<  SomeBase
>> def initialize
>> super
>> remote[:v] = 1
>> end
>>
>> def inc
>> remote[:v] += 1
>> end
>>
>> def magic
>> do_something(remote[:v])
>> end
>> end
>>
>> Or:
>>
>> class A<  SomeBase
>> def initialize
>> super
>> remote.v = 1
>> end
>>
>> def inc
>> remote.v += 1
>> end
>>
>> def magic
>> do_something(remote.v)
>> end
>> end
>>
>>
>> It makes it a bit more obvious what's happening. The other benefit of this method is that it's not required to declare these with magic_accessor, as whatever #remote returns can deal magically with #[]/#[]= or #method_missing.
>>
>
> I'm not quite getting the remote thing -- is this a ruby-ism, a
> variable, a method, what? Doing a google on "ruby remote" doesn't get
> me anything that I can make sense of this.

The suggestion is essentially to create a Ruby class that uses the array 
ops ("[]" and "[]=") to manipulate the remote user variables, which 
coincidentally was in the same style as the present solution at the time 
of my original post. :)

An implementation for the class Remote might look like this:

class Remote
   def initialize ...
     ...
   end

   def []= a, v
     @server.sendVariableWriteMessage a, v
   end

   def [] a
     return @server.sendVariableReadMessage a
   end
end

And we create a remote object for each instance of A:

class A <SomeBase
   def initialize
     super
     @remote = Remote.new ...
   end
   ...

   attr_reader :remote
end

ie. each object has a remote object attached to it, and you use "remote" 
explicitly whenever you want to manipulate one of the remotely-stored 
variables. For example, the line:

remote[:v] = 1

would use the remote object, call the "[]=" method on it, which would 
cause the variable to be sent to the server.

My question is, essentially, what ways could the problem I mentioned in 
my original post be solved with user convenience as a goal, and this is 
one potential solution.

So, in answer to your question, "remote" isn't a Rubyism as such, it's 
just the name of the object we're using, but treating it like an array 
(with "[]" and "[]=" ops) is a Rubyism.

I hope this helps. :)

Cheers,
Garth