Class: SerializableProc::Binding

Inherits:
Object
  • Object
show all
Includes:
Isolatable, Marshalable
Defined in:
lib/serializable_proc/binding.rb

Instance Method Summary collapse

Methods included from Marshalable

included

Constructor Details

#initialize(binding, sexp) ⇒ Binding

Returns a new instance of Binding.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/serializable_proc/binding.rb', line 11

def initialize(binding, sexp)
  sexp, @vars = sexp.gsub(s(:scope, s(:block, SexpAny.new)), nil), {}
  types = isolated_types(sexp)
  unless types.empty?
    sexp_str = sexp.inspect
    while m = sexp_str.match(/^(.*?s\(:(?:#{types.join('|')})var, :([^\)]+)\))/)
      ignore, var = m[1..2]
      sexp_str.sub!(ignore,'')
      next unless isolatable?(var)
      begin
        val = eval(var, binding) rescue nil
        @vars.update(isolated_var(var) => mclone(val))
      rescue TypeError
        raise CannotSerializeVariableError.new("Variable #{var} cannot be serialized !!")
      end
    end
  end
end

Instance Method Details

#eval!(binding = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/serializable_proc/binding.rb', line 30

def eval!(binding = nil)
  unless binding
    @binding ||= (
      eval(declare_vars, binding = Kernel.binding)
      binding
    )
  else
    eval(declare_vars, binding)
    binding
  end
end