instance_methods.each do |m|
next if ignore.include? m
module_eval <<-code
def #{ m } *a, &b
__obj.send "#{ m }", *a, &b
end
code
end
attr_accessor '__obj'
def initialize obj
self.__obj = obj
end
end
a = String::new '42'
b = Proxy::new a
p a.class
p b.class
p(a.methods == b.methods)
harp:~ > ruby a.rb
String
true
hth.
-a
···
On Fri, 14 Oct 2005, Jeff Wood wrote:
I think I've got a very challenging project on my hands but here's I'm
trying to create.
I want a completely clean(transparent) proxy object.
One where ALL methods simply return the result of the same call on the
proxied ( not the proxy ) object.
I mean, if the user wants to add/override methods, that's fine, but by
default, EVERY call should be passed through.
I hope that makes sense...
So:
a = String
b = Proxy.new( a )
# should be the same
a.class
b.class
# should be the same
a.methods
b.methods
I want it be completely transparent.
Is that possible?
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
I want a completely clean(transparent) proxy object.
The controversial Ref class I made a while back on this list has this
property, I think, with the exception that it also has a deref property
which allows you to assign it a different delegate-object. You could remove
that interface, but I imagine it could be handy.
It just uses Delegate, and redefines is_a?, kind_of?, respond_to, and
Module#===.
harp:~ > cat a.rb
module Proxy
def self::new obj
klass = Class::new do
ignore = %w( __send__ __id__ )
obj.class.instance_methods.each do |m|
next if ignore.include? m
module_eval <<-code
def #{ m } *a, &b
__obj.send "#{ m }", *a, &b
end
code
end
attr_accessor '__obj'
def initialize obj
self.__obj = obj
end
self
end
klass::new obj
end
end
a = String::new 'forty-two'
b = Proxy::new a
p a.class
p b.class
p(a.methods == b.methods)
p b.upcase
harp:~ > ruby a.rb
String
true
"FORTY-TWO"
-a
···
On Fri, 14 Oct 2005, Ara.T.Howard wrote:
this'll be a good start:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
These are a good start, but what I'm really trying to do is come up with a
completely clean way to do DRb ...
Don't get me wrong, I love DRb for what it is, but I want transparent proxy.
So, I want to be able to do DRb::Proxy.new( "druby://add.ress:1234" )
and get back an object I can call methods on ... that will report it self as
whatever the Proxy is proxying not DRbObject ...
Does that make sense? I am wanting to be able to use irb with DRb and get
live auto-completion across the wire ...
I figure a transparent proxy is the ONLY way ...
let me know if I'm going down the wrong path.
j.
···
On 10/13/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:
On Fri, 14 Oct 2005, Ara.T.Howard wrote:
> this'll be a good start:
<snip backwards reply>
scratch that - try this:
harp:~ > cat a.rb
module Proxy
def self::new obj
klass = Class::new do
ignore = %w( __send__ __id__ )
obj.class.instance_methods.each do |m|
next if ignore.include? m
module_eval <<-code
def #{ m } *a, &b
__obj.send "#{ m }", *a, &b
end
code
end
attr_accessor '__obj'
def initialize obj
self.__obj = obj
end
self
end
klass::new obj
end
end
a = String::new 'forty-two'
b = Proxy::new a
p a.class
p b.class
p(a.methods == b.methods)
p b.upcase
harp:~ > ruby a.rb
String
String
true
"FORTY-TWO"
-a
--
===============================================================================
> email :: ara [dot] t [dot] howard [at] noaa [dot] gov
> phone :: 303.497.6469
> Your life dwells amoung the causes of death
> Like a lamp standing in a strong breeze. --Nagarjuna
well. you can, but's that's what drb is. what i'm driving at is that it
seems the proxy object you seek may only be wrapped around the local drb
object and, therfore, you'll be right back where you started from. which
object to you intend to wrap such that it would make it seem that the object
were local?
i think you'd need to hackery in the drb object itself - it has a notion of
which methods to forward and which not to. you could muck with this. i'm
unclear how a proxy would clarify the situation though...
regards.
-a
···
On Fri, 14 Oct 2005, Jeff Wood wrote:
These are a good start, but what I'm really trying to do is come up with a
completely clean way to do DRb ...
Don't get me wrong, I love DRb for what it is, but I want transparent proxy.
So, I want to be able to do DRb::Proxy.new( "druby://add.ress:1234" )
and get back an object I can call methods on ... that will report it self as
whatever the Proxy is proxying not DRbObject ...
Does that make sense? I am wanting to be able to use irb with DRb and get
live auto-completion across the wire ...
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
These are a good start, but what I'm really trying to do is come up with a
completely clean way to do DRb ...
It really helps when you say what you actually want to do
It seems as if the DRb object already works just like you want
except that it says it is a DRbObject when you do #inspect or
something? Or is there some other functionality that you need?
···
Don't get me wrong, I love DRb for what it is, but I want transparent proxy.
So, I want to be able to do DRb::Proxy.new( "druby://add.ress:1234" )
and get back an object I can call methods on ... that will report it self as
whatever the Proxy is proxying not DRbObject ...
Does that make sense? I am wanting to be able to use irb with DRb and get
live auto-completion across the wire ...
I figure a transparent proxy is the ONLY way ...
let me know if I'm going down the wrong path.
j.
On 10/13/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:
On Fri, 14 Oct 2005, Ara.T.Howard wrote:
this'll be a good start:
<snip backwards reply>
scratch that - try this:
harp:~ > cat a.rb
module Proxy
def self::new obj
klass = Class::new do
ignore = %w( __send__ __id__ )
obj.class.instance_methods.each do |m|
next if ignore.include? m
module_eval <<-code
def #{ m } *a, &b
__obj.send "#{ m }", *a, &b
end
code
end
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
Does this make any sense in the context of wanting something I can script
remotely against?
DRb has a disposition that you have to know what you are calling remotely
before you can call it ...
And, if you are wanting to pass a remote object into a function, you can't
do any duck-type checking because respond_to? is based on DRbObject, not the
remote object it is to proxy.
Anyways, that's the goal of the project, simply to be able to use DRb
transparently, completely transparently.
I look forward to any further suggestions you have, thanks for what you've
provided already.
j.
···
On 10/13/05, Jeff Wood <jeff.darklight@gmail.com> wrote:
Yeah, sorry.
I mean ...
a = 1
b = Proxy.new( a )
or
a = "Hello, World"
b = Proxy.new( a )
or
a = MyComplicatedObject.new
b = Proxy.new( a )
...
sorry for the mis-type ...
j.
On 10/13/05, David A. Black <dblack@wobblini.net> wrote:
>
> Hi --
>
> On Fri, 14 Oct 2005, Ara.T.Howard wrote:
>
> > a = String::new 'forty-two'
> > b = Proxy::new a
>
> That's not the original problem, though. It was:
>
> a = String
> b = Proxy.new(a)
>
> I guess you have the same hunch I do, that it was actually meant to be
> String.new.
>
>
> David
>
> --
> David A. Black
> dblack@wobblini.net
>
>
Actually I wrote a new chunk of code based on Ara's snippet that for direct
calls does EXACTLY what I want it to ... I'll be posting it later today ...
I just have to deal with stuff like blah.call.call2.call3 ... which I don't
believe will currently work ... I'll have to dig through and see how DRb
makes it work ...
DRbObjects don't work ... call methods or call respond_to? ... they are NOT
calls on the remote object ... I don't believe ANY call on a proxied object
should be local, they should ALL be passed over the wire ( and yes, I know
that at least id and send can't, but everything other than those ).
I really think you guys will like the stuff I have ... So far, I'm calling
it Roxy ...
Thanks.
j.
···
On 10/13/05, ES <ruby-ml@magical-cat.org> wrote:
Jeff Wood wrote:
> These are a good start, but what I'm really trying to do is come up with
a
> completely clean way to do DRb ...
It really helps when you say what you actually want to do
It seems as if the DRb object already works just like you want
except that it says it is a DRbObject when you do #inspect or
something? Or is there some other functionality that you need?
> Don't get me wrong, I love DRb for what it is, but I want transparent
proxy.
>
> So, I want to be able to do DRb::Proxy.new( "druby://add.ress:1234" )
>
> and get back an object I can call methods on ... that will report it
self as
> whatever the Proxy is proxying not DRbObject ...
>
> Does that make sense? I am wanting to be able to use irb with DRb and
get
> live auto-completion across the wire ...
>
> I figure a transparent proxy is the ONLY way ...
>
> let me know if I'm going down the wrong path.
>
> j.
>
> On 10/13/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:
>
>>On Fri, 14 Oct 2005, Ara.T.Howard wrote:
>>
>>
>>>this'll be a good start:
>>
>><snip backwards reply>
>>
>>scratch that - try this:
>>
>>harp:~ > cat a.rb
>>module Proxy
>>def self::new obj
>>klass = Class::new do
>>ignore = %w( __send__ __id__ )
>>
>>obj.class.instance_methods.each do |m|
>>next if ignore.include? m
>>module_eval <<-code
>>def #{ m } *a, &b
>>__obj.send "#{ m }", *a, &b
>>end
>>code
>>end
>>
>>attr_accessor '__obj'
>>
>>def initialize obj
>>self.__obj = obj
>>end
>>
>>self
>>end
>>klass::new obj
>>end
>>end
>>
>>a = String::new 'forty-two'
>>b = Proxy::new a
>>
>>p a.class
>>p b.class
>>
>>p(a.methods == b.methods)
>>
>>p b.upcase
>>
>>
>>harp:~ > ruby a.rb
>>String
>>String
>>true
>>"FORTY-TWO"
>>
>>
>>-a
>>--
>>
>>===============================================================================
>>> email :: ara [dot] t [dot] howard [at] noaa [dot] gov
>>> phone :: 303.497.6469
>>> Your life dwells amoung the causes of death
>>> Like a lamp standing in a strong breeze. --Nagarjuna
>>
>>===============================================================================
>>
>>
>>
>
>
>
> --
> "http://ruby-lang.org -- do you ruby?"
>
> Jeff Wood
>
In there is a modified version of Jim Weirich's BlankSlate. You can use
that as a base class, it removes all but a handful of methods (and may
remove even more in the future).
That is about the best you are going to achieve without a dispatch
mechinism, which Ruby does not have. And from what I understand won't
ever have b/c it would slow things down too much.
But, Ruby may get a bonafide Kernelless "ObjectShell" in the future.
Or to be specifically accurate, DRbObjects aren't transparent enough ...
they don't provide you with the list of available functionality
appropriately.
···
On 10/14/05, Jeff Wood <jeff.darklight@gmail.com> wrote:
Actually I wrote a new chunk of code based on Ara's snippet that for
direct calls does EXACTLY what I want it to ... I'll be posting it later
today ... I just have to deal with stuff like blah.call.call2.call3 ...
which I don't believe will currently work ... I'll have to dig through and
see how DRb makes it work ...
DRbObjects don't work ... call methods or call respond_to? ... they are
NOT calls on the remote object ... I don't believe ANY call on a proxied
object should be local, they should ALL be passed over the wire ( and yes, I
know that at least id and send can't, but everything other than those ).
I really think you guys will like the stuff I have ... So far, I'm
calling it Roxy ...
Thanks.
j.
On 10/13/05, ES <ruby-ml@magical-cat.org> wrote:
>
> Jeff Wood wrote:
> > These are a good start, but what I'm really trying to do is come up
> with a
> > completely clean way to do DRb ...
>
> It really helps when you say what you actually want to do
>
> It seems as if the DRb object already works just like you want
> except that it says it is a DRbObject when you do #inspect or
> something? Or is there some other functionality that you need?
>
> > Don't get me wrong, I love DRb for what it is, but I want transparent
> proxy.
> >
> > So, I want to be able to do DRb::Proxy.new( "druby://add.ress:1234" )
> >
> > and get back an object I can call methods on ... that will report it
> self as
> > whatever the Proxy is proxying not DRbObject ...
> >
> > Does that make sense? I am wanting to be able to use irb with DRb and
> get
> > live auto-completion across the wire ...
> >
> > I figure a transparent proxy is the ONLY way ...
> >
> > let me know if I'm going down the wrong path.
> >
> > j.
> >
> > On 10/13/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:
> >
> >>On Fri, 14 Oct 2005, Ara.T.Howard wrote:
> >>
> >>
> >>>this'll be a good start:
> >>
> >><snip backwards reply>
> >>
> >>scratch that - try this:
> >>
> >>harp:~ > cat a.rb
> >>module Proxy
> >>def self::new obj
> >>klass = Class::new do
> >>ignore = %w( __send__ __id__ )
> >>
> >>obj.class.instance_methods.each do |m|
> >>next if ignore.include? m
> >>module_eval <<-code
> >>def #{ m } *a, &b
> >>__obj.send "#{ m }", *a, &b
> >>end
> >>code
> >>end
> >>
> >>attr_accessor '__obj'
> >>
> >>def initialize obj
> >>self.__obj = obj
> >>end
> >>
> >>self
> >>end
> >>klass::new obj
> >>end
> >>end
> >>
> >>a = String::new 'forty-two'
> >>b = Proxy::new a
> >>
> >>p a.class
> >>p b.class
> >>
> >>p(a.methods == b.methods)
> >>
> >>p b.upcase
> >>
> >>
> >>harp:~ > ruby a.rb
> >>String
> >>String
> >>true
> >>"FORTY-TWO"
> >>
> >>
> >>-a
> >>--
> >>
>
> >>===============================================================================
> >>> email :: ara [dot] t [dot] howard [at] noaa [dot] gov
> >>> phone :: 303.497.6469
> >>> Your life dwells amoung the causes of death
> >>> Like a lamp standing in a strong breeze. --Nagarjuna
> >>
> >>===============================================================================
>
> >>
> >>
> >>
> >
> >
> >
> > --
> > "http://ruby-lang.org -- do you ruby?"
> >
> > Jeff Wood
> >
>
>
>
sounds neat - now that i understand what you're after. i guess that approach
would be find so long as one has __some__ method to determine what the heck
the object 'really' like:
proxy.__drb #=> the obj
proxy.__drb? #=> true
but i like the sound of making drb objects as close to local ones at possible.
look forward to seeing what you come up with.
-a
···
On Fri, 14 Oct 2005, Jeff Wood wrote:
Actually I wrote a new chunk of code based on Ara's snippet that for direct
calls does EXACTLY what I want it to ... I'll be posting it later today ...
I just have to deal with stuff like blah.call.call2.call3 ... which I don't
believe will currently work ... I'll have to dig through and see how DRb
makes it work ... DRbObjects don't work ... call methods or call
respond_to? ... they are NOT calls on the remote object ... I don't believe
ANY call on a proxied object should be local, they should ALL be passed over
the wire ( and yes, I know that at least id and send can't, but everything
other than those ). I really think you guys will like the stuff I have ...
So far, I'm calling it Roxy ...
Thanks.
j.
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna