From: Garthy D Date: 2012-11-23T09:12:15+09:00 Subject: Re: Instance-variable-like user API Hi, On 23/11/12 00:16, tamouse mailing lists wrote: > On Thu, Nov 22, 2012 at 3:55 AM, Arlen Cuss 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