Class: RemoteRuby::LocalsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/locals_extractor.rb

Overview

Extracts local variable from given context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, ignore_types: []) ⇒ LocalsExtractor

Returns a new instance of LocalsExtractor.



6
7
8
9
# File 'lib/remote_ruby/locals_extractor.rb', line 6

def initialize(block, ignore_types: [])
  @block = block
  @ignore_types = Array(ignore_types)
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/remote_ruby/locals_extractor.rb', line 4

def block
  @block
end

#ignore_typesObject (readonly)

Returns the value of attribute ignore_types.



4
5
6
# File 'lib/remote_ruby/locals_extractor.rb', line 4

def ignore_types
  @ignore_types
end

Instance Method Details

#localsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/remote_ruby/locals_extractor.rb', line 11

def locals
  locals = {}

  local_variable_names.each do |name|
    value = block.binding.eval(name.to_s)
    next if ignored_type?(value)
    locals[name] = value
  end

  locals
end