Documentation ¶
Index ¶
- type ArgumentError
- type Array
- type Boolean
- type CallContext
- type EnvEntryInfo
- type Environment
- type Exception
- type File
- type Function
- type FunctionParameter
- type Hash
- type Integer
- type LoadError
- type LocalJumpError
- type MethodSet
- type MethodVisibility
- type Module
- type NameError
- type NoMethodError
- type NotImplementedError
- type Object
- type Proc
- type ReturnValue
- type RubyClass
- type RubyClassObject
- type RubyMethod
- type RubyObject
- type RuntimeError
- type ScriptError
- type Self
- type SettableMethodSet
- type StandardError
- type String
- type Symbol
- type SyntaxError
- type Type
- type TypeError
- type ZeroDivisionError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgumentError ¶
type ArgumentError struct {
// contains filtered or unexported fields
}
ArgumentError represents an error in method call arguments
func NewArgumentError ¶
func NewArgumentError(format string, args ...interface{}) *ArgumentError
NewArgumentError creates an ArgumentError. It has the same API as fmt.Errorf
func NewWrongNumberOfArgumentsError ¶
func NewWrongNumberOfArgumentsError(expected, actual int) *ArgumentError
NewWrongNumberOfArgumentsError returns an ArgumentError populated with the default message
func (*ArgumentError) Class ¶
func (e *ArgumentError) Class() RubyClass
Class returns argumentErrorClass
func (*ArgumentError) Error ¶
func (e *ArgumentError) Error() string
func (*ArgumentError) Inspect ¶
func (e *ArgumentError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type Array ¶
type Array struct {
Elements []RubyObject
}
An Array represents a Ruby Array
func NewArray ¶
func NewArray(elements ...RubyObject) *Array
NewArray returns a new array populated with elements.
type Boolean ¶
type Boolean struct {
Value bool
}
Boolean represents a Boolean object in Ruby
type CallContext ¶
type CallContext interface { // Env returns the current environment at call time Env() Environment // Eval represents an evalualtion method suitable to eval arbitrary Ruby // AST Nodes and transform them into a resulting Ruby object or an error. Eval(ast.Node, Environment) (RubyObject, error) // Receiver returns the Ruby object the message is sent to Receiver() RubyObject }
CallContext represents the context information when sending a message to an object.
func NewCallContext ¶
func NewCallContext(env Environment, receiver RubyObject) CallContext
NewCallContext returns a new CallContext with a stubbed eval function
type EnvEntryInfo ¶
type EnvEntryInfo interface { Name() string Env() Environment }
EnvEntryInfo describes an entry in an Environment and is returned by EnvStat
func EnvStat ¶
func EnvStat(env Environment, obj RubyObject) (EnvEntryInfo, bool)
EnvStat returns the EnvEntryInfo for obj. If obj is not found in the hierarchy of env, the bool will be false.
type Environment ¶
type Environment interface { // Get returns the RubyObject found for this key. If it is not found, // ok will be false Get(key string) (object RubyObject, ok bool) // GetAll returns all values for the current env as a map of string to RubyObject GetAll() map[string]RubyObject // Set sets the RubyObject for the given key. If there is already an // object with that key it will be overridden by object Set(key string, object RubyObject) RubyObject // Unset removes the entry for the given key. It returns the removed entry Unset(key string) RubyObject // SetGlobal sets val under name at the root of the environment SetGlobal(name string, val RubyObject) RubyObject // Outer returns the parent environment Outer() Environment // Clone returns a copy of the environment. It will shallow copy its values // // Note that clone will not set its outer env, so calls to Outer will // return nil on cloned Environments Clone() Environment }
Environment holds Ruby object referenced by strings
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer Environment) Environment
NewEnclosedEnvironment returns an Environment wrapped by outer
func NewEnvironment ¶
func NewEnvironment() Environment
NewEnvironment returns a new Environment ready to use
func NewMainEnvironment ¶
func NewMainEnvironment() Environment
NewMainEnvironment returns a new Environment populated with all Ruby classes and the Kernel functions
func WithScopedLocalVariables ¶
func WithScopedLocalVariables(e Environment) Environment
WithScopedLocalVariables returns an Environment which scopes the local variables within another env so they cannot leak out
type Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
Exception represents a basic exception
func NewException ¶
NewException creates a new exception with the given message template and uses fmt.Sprintf to interpolate the args into messageinto message.
type File ¶
type File struct {
Map map[RubyObject]RubyObject
}
A File represents the Ruby class File
type Function ¶
type Function struct { Parameters []*FunctionParameter Body *ast.BlockStatement Env Environment MethodVisibility MethodVisibility }
A Function represents a user defined function. It is no real Ruby object.
func (*Function) Call ¶
func (f *Function) Call(context CallContext, args ...RubyObject) (RubyObject, error)
Call implements the RubyMethod interface. It evaluates f.Body and returns its result
func (*Function) Visibility ¶
func (f *Function) Visibility() MethodVisibility
Visibility implements the RubyMethod interface. It returns f.MethodVisibility
type FunctionParameter ¶
type FunctionParameter struct { Name string Default RubyObject }
FunctionParameter represents a parameter within a function
func (*FunctionParameter) String ¶
func (f *FunctionParameter) String() string
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
A Hash represents a Ruby Hash
func (*Hash) Get ¶
func (h *Hash) Get(key RubyObject) (RubyObject, bool)
Get retrieves the object for key within the hash. If not found, the boolean will be false
func (*Hash) Inspect ¶
Inspect returns all elements within the array, divided by comma and surrounded by brackets
func (*Hash) Map ¶
func (h *Hash) Map() map[RubyObject]RubyObject
Map returns a map of RubyObject to RubyObject
func (*Hash) Set ¶
func (h *Hash) Set(key, value RubyObject) RubyObject
Set puts the object obj into the Hash
type Integer ¶
type Integer struct {
Value int64
}
Integer represents an integer in Ruby
func NewInteger ¶
NewInteger returns a new Integer with the given value
type LoadError ¶
type LoadError struct {
// contains filtered or unexported fields
}
LoadError represents an error while loading another file
func NewNoSuchFileLoadError ¶
NewNoSuchFileLoadError returns a new LoadError with the default message
type LocalJumpError ¶
type LocalJumpError struct {
// contains filtered or unexported fields
}
LocalJumpError represents an error for a not supported jump
func NewNoBlockGivenLocalJumpError ¶
func NewNoBlockGivenLocalJumpError() *LocalJumpError
NewNoBlockGivenLocalJumpError returns a LocalJumpError with the default message for missing blocks
func (*LocalJumpError) Class ¶
func (e *LocalJumpError) Class() RubyClass
Class returns notImplementedErrorClass
func (*LocalJumpError) Error ¶
func (e *LocalJumpError) Error() string
func (*LocalJumpError) Inspect ¶
func (e *LocalJumpError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type MethodSet ¶
type MethodSet interface { // Get returns the method found for name. The boolean will return true if // a method was found, false otherwise Get(name string) (RubyMethod, bool) // GetAll returns a map of name to methods representing the MethodSet. GetAll() map[string]RubyMethod }
MethodSet represents a set of methods
type MethodVisibility ¶
type MethodVisibility visibility
MethodVisibility represents the visibility of a method
const ( // PUBLIC_METHOD declares that a method is visible from the outside of an object PUBLIC_METHOD MethodVisibility = iota // PROTECTED_METHOD declares that a method is not visible from the outside // of an object but to all of its decendents PROTECTED_METHOD // PRIVATE_METHOD declares that a method is not visible from the outside // of an object and not to all of its decendents PRIVATE_METHOD )
type Module ¶
type Module struct { Environment // contains filtered or unexported fields }
Module represents a module in Ruby
func NewModule ¶
func NewModule(name string, outerEnv Environment) *Module
NewModule returns a new module with the given name and adds methods to its method set.
type NameError ¶
type NameError struct {
// contains filtered or unexported fields
}
A NameError represents an error accessing an identifier unknown to the environment
func NewUndefinedLocalVariableOrMethodNameError ¶
func NewUndefinedLocalVariableOrMethodNameError(context RubyObject, name string) *NameError
NewUndefinedLocalVariableOrMethodNameError returns a NameError with the default message for undefined names
func NewUninitializedConstantNameError ¶
NewUninitializedConstantNameError returns a NameError with the default message for uninitialized constants
type NoMethodError ¶
type NoMethodError struct {
// contains filtered or unexported fields
}
NoMethodError represents an error finding a fitting method on an object
func NewNoMethodError ¶
func NewNoMethodError(context RubyObject, method string) *NoMethodError
NewNoMethodError returns a NoMethodError with the default message for undefined methods
func NewPrivateNoMethodError ¶
func NewPrivateNoMethodError(context RubyObject, method string) *NoMethodError
NewPrivateNoMethodError returns a NoMethodError with the default message for private methods
func (*NoMethodError) Class ¶
func (e *NoMethodError) Class() RubyClass
Class returns noMethodErrorClass
func (*NoMethodError) Error ¶
func (e *NoMethodError) Error() string
func (*NoMethodError) Inspect ¶
func (e *NoMethodError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type NotImplementedError ¶
type NotImplementedError struct {
// contains filtered or unexported fields
}
NotImplementedError represents an error for a not implemented feature on a given platform
func NewNotImplementedError ¶
func NewNotImplementedError(format string, args ...interface{}) *NotImplementedError
NewNotImplementedError returns a NotImplementedError with the provided message
func (*NotImplementedError) Class ¶
func (e *NotImplementedError) Class() RubyClass
Class returns notImplementedErrorClass
func (*NotImplementedError) Error ¶
func (e *NotImplementedError) Error() string
func (*NotImplementedError) Inspect ¶
func (e *NotImplementedError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
func (*NotImplementedError) Type ¶
func (e *NotImplementedError) Type() Type
Type returns EXCEPTION_OBJ
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents an Object in Ruby
type Proc ¶
type Proc struct { Parameters []*ast.FunctionParameter Body *ast.BlockStatement Env Environment ArgumentCountMandatory bool }
A Proc represents a user defined block of code.
func (*Proc) Call ¶
func (p *Proc) Call(context CallContext, args ...RubyObject) (RubyObject, error)
Call implements the RubyMethod interface. It evaluates p.Body and returns its result
type ReturnValue ¶
type ReturnValue struct {
Value RubyObject
}
ReturnValue represents a wrapper object for a return statement. It is no real Ruby object and only used within the interpreter evaluation
func (*ReturnValue) Class ¶
func (rv *ReturnValue) Class() RubyClass
Class reurns the class of the wrapped object
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
Inspect returns the string representation of the wrapped object
type RubyClass ¶
type RubyClass interface { Methods() MethodSet SuperClass() RubyClass New(args ...RubyObject) (RubyObject, error) Name() string }
RubyClass represents a class in Ruby
type RubyClassObject ¶
type RubyClassObject interface { RubyObject RubyClass }
RubyClassObject represents a class object in Ruby
func NewClass ¶
func NewClass(name string, superClass RubyClass, env Environment) RubyClassObject
NewClass returns a new Ruby Class
type RubyMethod ¶
type RubyMethod interface { Call(context CallContext, args ...RubyObject) (RubyObject, error) Visibility() MethodVisibility }
RubyMethod defines a Ruby method
type RubyObject ¶
type RubyObject interface { Type() Type Class() RubyClass // contains filtered or unexported methods }
RubyObject represents an object in Ruby
var ( // TRUE represents the singleton object for the Boolean true TRUE RubyObject = &Boolean{Value: true} // FALSE represents the singleton object for the Boolean false FALSE RubyObject = &Boolean{Value: false} )
var ( // NIL represents the singleton object nil NIL RubyObject = &nilObject{} )
func AddMethod ¶
func AddMethod(context RubyObject, methodName string, method *Function) RubyObject
AddMethod adds a method to a given object. It returns the object with the modified method set
func Send ¶
func Send(context CallContext, method string, args ...RubyObject) (RubyObject, error)
Send sends message method with args to context and returns its result
type RuntimeError ¶
type RuntimeError struct {
// contains filtered or unexported fields
}
RuntimeError is a generic error class raised when an invalid operation is attempted
func NewRuntimeError ¶
func NewRuntimeError(format string, args ...interface{}) *RuntimeError
NewRuntimeError returns a new RuntimeError with the formatted message
func (*RuntimeError) Class ¶
func (e *RuntimeError) Class() RubyClass
Class returns runtimeErrorClass
func (*RuntimeError) Error ¶
func (e *RuntimeError) Error() string
func (*RuntimeError) Inspect ¶
func (e *RuntimeError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type ScriptError ¶
type ScriptError struct {
// contains filtered or unexported fields
}
ScriptError represetns an error in the loaded script
func NewScriptError ¶
func NewScriptError(format string, args ...interface{}) *ScriptError
NewScriptError returns a new script error with the provided message
func (*ScriptError) Error ¶
func (e *ScriptError) Error() string
func (*ScriptError) Inspect ¶
func (e *ScriptError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type Self ¶
type Self struct { RubyObject // The encapsuled object acting as self Block *Proc // the block given to the current execution binding Name string // The name of self in this context }
Self represents the value associated to `self`. It acts as a wrapper around the RubyObject and is just meant to indicate that the given object is self in the given context.
type SettableMethodSet ¶
type SettableMethodSet interface { MethodSet // Set will set method to key name. If there was a method prior defined // under name it will be overridden. Set(name string, method RubyMethod) }
SettableMethodSet represents a MethodSet which can be mutated by setting methods on it.
func NewMethodSet ¶
func NewMethodSet(methods map[string]RubyMethod) SettableMethodSet
NewMethodSet returns a new method set populated with the given methods
type StandardError ¶
type StandardError struct {
// contains filtered or unexported fields
}
StandardError is the default class for rescue blocks
func NewStandardError ¶
func NewStandardError(message string) *StandardError
NewStandardError returns a StandardError with the given message
func (*StandardError) Class ¶
func (e *StandardError) Class() RubyClass
Class returns standardErrorClass
func (*StandardError) Error ¶
func (e *StandardError) Error() string
func (*StandardError) Inspect ¶
func (e *StandardError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError represents a syntax error in the ruby scripts
func NewSyntaxError ¶
func NewSyntaxError(syntaxError error) *SyntaxError
NewSyntaxError returns a new SyntaxError with the default message
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
func (*SyntaxError) Inspect ¶
func (e *SyntaxError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message
func (*SyntaxError) UnderlyingError ¶
func (e *SyntaxError) UnderlyingError() error
UnderlyingError returns the parser error wrapped by SyntaxError
type Type ¶
type Type string
Type represents a type of an object
const ( EIGENCLASS_OBJ Type = "EIGENCLASS" FUNCTION_OBJ Type = "FUNCTION" RETURN_VALUE_OBJ Type = "RETURN_VALUE" BASIC_OBJECT_OBJ Type = "BASIC_OBJECT" OBJECT_OBJ Type = "OBJECT" CLASS_OBJ Type = "CLASS" CLASS_INSTANCE_OBJ Type = "CLASS" ARRAY_OBJ Type = "ARRAY" HASH_OBJ Type = "HASH" INTEGER_OBJ Type = "INTEGER" STRING_OBJ Type = "STRING" SYMBOL_OBJ Type = "SYMBOL" BOOLEAN_OBJ Type = "BOOLEAN" NIL_OBJ Type = "NIL" NIL_CLASS_OBJ Type = "NIL_CLASS" EXCEPTION_OBJ Type = "EXCEPTION" MODULE_OBJ Type = "MODULE" SELF Type = "SELF" )
type TypeError ¶
type TypeError struct {
// contains filtered or unexported fields
}
TypeError represents an error when the given type does not fit in the given context
func NewCoercionTypeError ¶
func NewCoercionTypeError(expected, actual RubyObject) *TypeError
NewCoercionTypeError returns a TypeError with the default message for coercing errors
func NewImplicitConversionTypeError ¶
func NewImplicitConversionTypeError(expected, actual RubyObject) *TypeError
NewImplicitConversionTypeError returns a TypeError with the default message for impossible implicit conversions
func NewTypeError ¶
NewTypeError returns a TypeError with the provided message
func NewWrongArgumentTypeError ¶
func NewWrongArgumentTypeError(expected, actual RubyObject) *TypeError
NewWrongArgumentTypeError returns a TypeError with the default message for wrong arugument type errors
type ZeroDivisionError ¶
type ZeroDivisionError struct {
// contains filtered or unexported fields
}
ZeroDivisionError represents an arithmethic error when dividing through 0
func NewZeroDivisionError ¶
func NewZeroDivisionError() *ZeroDivisionError
NewZeroDivisionError returns a new ZeroDivisionError with the default message
func (*ZeroDivisionError) Class ¶
func (e *ZeroDivisionError) Class() RubyClass
Class returns zeroDivisionErrorClass
func (*ZeroDivisionError) Error ¶
func (e *ZeroDivisionError) Error() string
func (*ZeroDivisionError) Inspect ¶
func (e *ZeroDivisionError) Inspect() string
Inspect returns a string starting with the exception class name, followed by the message