Class: EleetScript::BaseContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lang/runtime/context.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BaseContext

Returns a new instance of BaseContext.



21
22
23
24
# File 'lib/lang/runtime/context.rb', line 21

def initialize(*args)
  init(args)
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/lang/runtime/context.rb', line 86

def method_missing(name, *args)
  if @parent_context && @parent_context.respond_to?(name)
    @parent_context.send(name, *args)
  else
    super(name, *args)
  end
end

Class Attribute Details

.init_funcsObject (readonly)

Returns the value of attribute init_funcs.



9
10
11
# File 'lib/lang/runtime/context.rb', line 9

def init_funcs
  @init_funcs
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



5
6
7
# File 'lib/lang/runtime/context.rb', line 5

def constants
  @constants
end

#current_classObject

Returns the value of attribute current_class.



6
7
8
# File 'lib/lang/runtime/context.rb', line 6

def current_class
  @current_class
end

#current_selfObject

Returns the value of attribute current_self.



6
7
8
# File 'lib/lang/runtime/context.rb', line 6

def current_self
  @current_self
end

#global_varsObject (readonly)

Returns the value of attribute global_vars.



5
6
7
# File 'lib/lang/runtime/context.rb', line 5

def global_vars
  @global_vars
end

#local_varsObject (readonly)

Returns the value of attribute local_vars.



5
6
7
# File 'lib/lang/runtime/context.rb', line 5

def local_vars
  @local_vars
end

#namespacesObject (readonly)

Returns the value of attribute namespaces.



5
6
7
# File 'lib/lang/runtime/context.rb', line 5

def namespaces
  @namespaces
end

Class Method Details

.init_with(*func_symbols) ⇒ Object



11
12
13
14
# File 'lib/lang/runtime/context.rb', line 11

def init_with(*func_symbols)
  (@init_funcs ||= [])
  @init_funcs += func_symbols
end

Instance Method Details

#[](key) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/lang/runtime/context.rb', line 66

def [](key)
  store = fetch_var_store(key)
  if store[key]
    store[key]
  elsif @parent_context
    @parent_context[key]
  else
    es_nil
  end
end

#[]=(key, value) ⇒ Object



77
78
79
80
# File 'lib/lang/runtime/context.rb', line 77

def []=(key, value)
  store = fetch_var_store(key)
  store[key] = value
end

#class_varsObject



46
47
48
# File 'lib/lang/runtime/context.rb', line 46

def class_vars
  @current_self.class_vars
end

#es_nilObject



26
27
28
# File 'lib/lang/runtime/context.rb', line 26

def es_nil
  @_es_nil ||= root_ns["nil"]
end

#instance_varsObject



42
43
44
# File 'lib/lang/runtime/context.rb', line 42

def instance_vars
  @current_self.instance_vars
end

#local_constant(name) ⇒ Object



62
63
64
# File 'lib/lang/runtime/context.rb', line 62

def local_constant(name)
  constants[name] || es_nil
end

#local_var(name, value = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/lang/runtime/context.rb', line 54

def local_var(name, value = nil)
  if value
    local_vars[name] = value
  else
    local_vars[name] || es_nil
  end
end

#namespace_contextObject



50
51
52
# File 'lib/lang/runtime/context.rb', line 50

def namespace_context
  root_ns
end

#respond_to_missing?(name, incl_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/lang/runtime/context.rb', line 82

def respond_to_missing?(name, incl_priv = false)
  @parent_context && @parent_context.respond_to?(name, incl_priv)
end

#root_nsObject



30
31
32
# File 'lib/lang/runtime/context.rb', line 30

def root_ns
  @parent_context ? @parent_context.root_ns : nil
end