RAA - script/0.3

script / 0.3

Short description: Wrapper modules for loaded scripts
Category: Library/Development
Status: beta
Created: 2004-12-06 02:57:48 GMT
Last update: 2008-07-07 05:30:45 GMT
Owner: Joel VanderWerf (Projects of this owner)
Homepage: http://redshift.sourceforge.net/script/
Download: http://redshift.sourceforge.net/script/
License: Ruby's
Dependency:
None
Description:

Script 0.3

  • New examples.
  • Changed names of #main_file, #dir, and #loaded_features to be prefixed with __ to avoid conflicts.
  • Local variables in the top level script file are avaiable through the __script_scope method. See examples and docs.

Script 0.2

  • Fixed bug with making module function out of top-level method defs.

Script

Script is a subclass of Module. A module which is an instance of the Script class encapsulates in its scope the top-level methods, top-level constants, and instance variables defined in a ruby script file (and its dependent files) loaded by a ruby program. This allows use of script files to define objects that can be loaded into a program in much the same way that objects can be loaded from YAML or Marshal files. There is also an autoscript method which functions like ruby’s autoload but based on is Script.load (see examples/autoload-example.rb).

The implementation of Script is very simple, consisting of about 60 lines of code.

Synopsis

  • program.rb:
      require 'script'
      my_script = Script.load("my-script.rb")
      p my_script::VALUE
      my_script.run
    

  • my-script.rb:
      VALUE = [1,2,3]
      def run
        puts "#{self} running."
      end
    

  • output:
      $ ruby program.rb
      [1, 2, 3]
      #<Script:/tmp/my-script.rb> running.
    
Versions: [0.3 (2008-07-07)] [0.2 (2005-01-19)] [0.1 (2004-12-06)]

Edit this project (for project owner)

back to RAA top