module Gamefic::Scriptable

The Scriptable module provides a clean room (aka “theater”) for scripts.

@!method stage(*args, &block)

Execute a block of code in a subset of the owner's scope.

The provided code is evaluated inside a clean room object that has its
own instance variables and access to the owner's public methods. The proc
can accept the method call's arguments.

@example Execute a block of code
  stage {
    puts 'Hello'
  }

@example Execute a block of code with arguments
  stage 'hello' { |message|
    puts message # <- prints 'hello'
  }

@example Use an instance variable
  stage { @message = 'hello'" }
  stage { puts @message } # <- prints 'hello'

@yieldpublic [Gamefic::Plot]
@return [Object] The value returned by the executed code

@!method theater

The object that acts as an isolated namespace for staged code.
@return [Object]

@!parse alias cleanroom theater

Public Class Methods

included(klass) click to toggle source
# File lib/gamefic/scriptable.rb, line 53
def self.included klass
  klass.extend ClassMethods
end

Private Instance Methods

run_scripts() click to toggle source

Execute all the scripts that were added by the `script` class method.

# File lib/gamefic/scriptable.rb, line 61
def run_scripts
  self.class.blocks.each { |blk| stage &blk }
end