Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Dynamically load methods from external source

Reply
Thread Tools

Dynamically load methods from external source

 
 
Daniel Shackelford
Guest
Posts: n/a
 
      01-10-2007
I know this sounds like it could be a very bad thing to do, but I was
wondering if there is a way to load methods into an already running app
from an external source (database/file). I am building an app that
would load needed code snippets for a given task, but each time it runs
it will not need all the snippets, just certain ones. I know that I can
store the code as text in the database/file, but will I have to execute
it externally (via system 'ruby file.rb arg1 arg2'), or can I load and
execute it internally (possibly in a separate thread)? I can think of
all sorts of reasons why to NOT do this, but still, there is curiosity
isn't there..

I am thinking that somehow Rails does something like this with it's
controllers, but heck, that is a lot of code to sort through.

--
Daniel Shackelford
Systems Administrator
Technology Services
Spring Arbor University



 
Reply With Quote
 
 
 
 
Dr. D
Guest
Posts: n/a
 
      01-10-2007

I have a long running ruby process which does just this. There's a drb
port open on the process. If a method is changed, I open an irb
session, connect to drb, and run "load" on the remote process to reload
the file containing the changed methods. To reduce the typing I have
an rload method in the object exposed by drb.


Daniel Shackelford wrote:
> I know this sounds like it could be a very bad thing to do, but I was
> wondering if there is a way to load methods into an already running app
> from an external source (database/file). I am building an app that
> would load needed code snippets for a given task, but each time it runs
> it will not need all the snippets, just certain ones. I know that I can
> store the code as text in the database/file, but will I have to execute
> it externally (via system 'ruby file.rb arg1 arg2'), or can I load and
> execute it internally (possibly in a separate thread)? I can think of
> all sorts of reasons why to NOT do this, but still, there is curiosity
> isn't there..
>
> I am thinking that somehow Rails does something like this with it's
> controllers, but heck, that is a lot of code to sort through.
>
> --
> Daniel Shackelford
> Systems Administrator
> Technology Services
> Spring Arbor University


 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      01-10-2007
On 1/10/07, Daniel Shackelford <> wrote:
> I know this sounds like it could be a very bad thing to do, but I was
> wondering if there is a way to load methods into an already running app
> from an external source (database/file). I am building an app that
> would load needed code snippets for a given task, but each time it runs
> it will not need all the snippets, just certain ones. I know that I can
> store the code as text in the database/file, but will I have to execute
> it externally (via system 'ruby file.rb arg1 arg2'), or can I load and
> execute it internally (possibly in a separate thread)? I can think of
> all sorts of reasons why to NOT do this, but still, there is curiosity
> isn't there..
>
> I am thinking that somehow Rails does something like this with it's
> controllers, but heck, that is a lot of code to sort through.


use Kernel#eval for loading* code from string,
load/require to load code from file.
(require will load just once, load will more times)

loading = load and execute

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Question regarding how to dynamically change external javascript source information vfpuglia@gmail.com Javascript 3 02-09-2007 02:35 AM
Load User Control Dynamically, Cast object dynamically =?Utf-8?B?UmV6YSBOYWJp?= ASP .Net 1 03-05-2005 12:04 AM
Load User Control Dynamically, Cast object dynamically =?Utf-8?B?UmV6YSBOYWJp?= ASP .Net 1 03-04-2005 07:57 PM
Why Petshop Changed all static methods to instance methods when upgrading from version 3.0 to version 3.1? Neo ASP .Net 1 01-07-2005 01:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57