Ask a Question related to Ruby, Design and Development.
-
John #1
Getting references
How does one get a reference to a previously created object?
Here's the scenario. I'm writing a web application, so there's a
listener object that listens to incoming requests and spins off a
thread for each request. Each thread has a Context object, which holds
things like POST arguments, browser type, etc.
Suppose a request comes in, a thread is spun, and it finds a template
object for that page, fills it with text from a database, and now I
want to run macros. Finding and running macros is ridiculously easy
due to Ruby's regex support. But I want macros to have access to the
Context in which they are running. Is there any way to do this aside
from passing a reference along with each call?
John Guest
-
Web References
hi, There are 10 machines which run the same webservice. I have 10 webreferences in my client. Only during runtime, will i decide which webservice... -
[PHP-DEV] References
The current support for references is mediocre at best. For instance: class foobar { var $variable; function foobar() { $variable =... -
ASP.net using UNC references and IIS 5.0
I am having trouble getting ANY asp.net application (either .aspx or .asmx) working when IIS is configured to use a "share located on another... -
references help
Hi, I need some desperate help with my references usage in the code below. I'd appreciate the help enormously. Following is the input in the... -
references
Ok lets see I have the following two functions one calls the other Function a (&$myref) { ...something... then calls function b b($myref); ... -
ts #2
Re: Getting references
>>>>> "J" == John <gruby@sysarchitects.com> writes:
J> thread for each request. Each thread has a Context object, which holds
J> things like POST arguments, browser type, etc.
Well, if each thread has a Context object then you can store it as a
thread local variable
J> due to Ruby's regex support. But I want macros to have access to the
J> Context in which they are running. Is there any way to do this aside
J> from passing a reference along with each call?
retrieve the thread local variable, something like
svg% cat b.rb
#!/usr/bin/ruby
def retrieve
puts Thread.current['context']
end
Thread.new { Thread.current['context'] = 12; retrieve }
Thread.new { Thread.current['context'] = 24; retrieve }
svg%
svg% b.rb
12
24
svg%
--
Guy Decoux
ts Guest
-
Robert Klemme #3
Re: Getting references
"ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
news:rfc8yn19wjr.fsf@moulon.inra.fr...holds>> >>>>> "J" == John <gruby@sysarchitects.com> writes:
> J> thread for each request. Each thread has a Context object, whichYeah. Another option is to have a macro interpreter that knows about the> J> things like POST arguments, browser type, etc.
>
> Well, if each thread has a Context object then you can store it as a
> thread local variable
>
> J> due to Ruby's regex support. But I want macros to have access to the
> J> Context in which they are running. Is there any way to do this aside
> J> from passing a reference along with each call?
>
> retrieve the thread local variable, something like
>
> svg% cat b.rb
> #!/usr/bin/ruby
>
> def retrieve
> puts Thread.current['context']
> end
>
> Thread.new { Thread.current['context'] = 12; retrieve }
> Thread.new { Thread.current['context'] = 24; retrieve }
> svg%
>
> svg% b.rb
> 12
> 24
> svg%
context:
class MacroInterpreter
attr_accessor :context
def expand(macro)
# ...
end
end
Then you have to set it only once and you are not dependend on the thread.
IMHO this is cleaner than passing a hidden method argument / hidden global
(which a thread local effectively is).
Kind regards
robert
Robert Klemme Guest



Reply With Quote

