From: Robert Klemme Date: 2009-09-06T22:00:10+09:00 Subject: Re: Opinion: Scripting in a Ruby program On 06.09.2009 13:47, Tristan Shelton wrote: > Hello all, I'm working on a small program -- and learning to love Ruby > all over again -- but I've come across a small dilemma: What if you want > to make a Ruby program that can be extended without modifying the > original code? That is, a Ruby script that can itself be scripted. > > What I'm thinking of is something that gives users the ability to do > basic math, access explicitly allowed methods and properties and maybe > even allow user defined variables available only to that script, while > disallowing any other use of the parent Ruby script. Something that is > to Ruby what Ruby, Perl and Python are to C/C++. > > I considered loading chunks of Ruby script and using eval() in a safe > context, and also considered creating a very simple interpreted > scripting language in Ruby, but before I proceed with either option I > would like to pose this question to fellow Ruby enthusiasts: How would > you handle making a scriptable/extensible Ruby program like this? It seems like you just create a bunch of documented (!) classes and let users decide how they will use them. You can even go as far as providing a full script where the user can provide a main class name and invoke a method on that instead of your library provided main class. Generally in the Ruby world we tend to impose less restrictions on class and object usage. If someone abuses the code, then that's their decision. If it does not work, well... You get the picture. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/