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.



8
9
10
11
# File 'lib/remote_ruby/locals_extractor.rb', line 8

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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#ignore_typesObject (readonly)

Returns the value of attribute ignore_types.



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

def ignore_types
  @ignore_types
end

Instance Method Details

#localsObject



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

def locals
  locals = {}

  block.binding.local_variables.each do |name|
    value = block.binding.eval(name.to_s)
    next if ignored_type?(value)

    locals[name] = value
  end

  locals
end