Class: Binding

Inherits:
Object show all
Defined in:
opal/opal/corelib/binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jseval, scope_variables, receiver, source_location) ⇒ Binding

Returns a new instance of Binding.



3
4
5
6
# File 'opal/opal/corelib/binding.rb', line 3

def initialize(jseval, scope_variables, receiver, source_location)
  @jseval, @scope_variables, @receiver, @source_location = \
    jseval, scope_variables, receiver, source_location
end

Instance Attribute Details

#receiverObject (readonly)

Returns the value of attribute receiver.



40
41
42
# File 'opal/opal/corelib/binding.rb', line 40

def receiver
  @receiver
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



40
41
42
# File 'opal/opal/corelib/binding.rb', line 40

def source_location
  @source_location
end

Instance Method Details

#eval(str, file = nil, line = nil) ⇒ Object



34
35
36
37
38
# File 'opal/opal/corelib/binding.rb', line 34

def eval(str, file = nil, line = nil)
  return receiver if str == 'self'

  Kernel.eval(str, self, file, line)
end

#js_eval(*args) ⇒ Object



8
9
10
11
12
13
14
# File 'opal/opal/corelib/binding.rb', line 8

def js_eval(*args)
  if @jseval
    @jseval.call(*args)
  else
    raise 'Evaluation on a Proc#binding is not supported'
  end
end

#local_variable_defined?(value) ⇒ Boolean

Returns:



30
31
32
# File 'opal/opal/corelib/binding.rb', line 30

def local_variable_defined?(value)
  @scope_variables.include?(value)
end

#local_variable_get(symbol) ⇒ Object



16
17
18
19
20
# File 'opal/opal/corelib/binding.rb', line 16

def local_variable_get(symbol)
  js_eval(symbol)
rescue Exception
  raise NameError, "local variable `#{symbol}' is not defined for #{inspect}"
end

#local_variable_set(symbol, value) ⇒ Object



22
23
24
# File 'opal/opal/corelib/binding.rb', line 22

def local_variable_set(symbol, value)
  js_eval(symbol, value)
end

#local_variablesObject



26
27
28
# File 'opal/opal/corelib/binding.rb', line 26

def local_variables
  @scope_variables
end