Class: TCOMethod::BlockExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/tco_method/block_extractor.rb

Overview

Object encapsulating the logic to extract the source code of a given block.

Constant Summary collapse

DO_STR =
"do".freeze
END_STR =
"end".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ BlockExtractor

Returns a new instance of BlockExtractor.



13
14
15
16
17
18
19
20
# File 'lib/tco_method/block_extractor.rb', line 13

def initialize(block)
  source = block.source
  type = block.lambda? ? :lambda : :proc
  start_offset, end_offset = determine_offsets(block, source)
  @source = "#{type} #{source[start_offset..end_offset]}"
rescue MethodSource::SourceNotFoundError => ex
  raise AmbiguousSourceError.wrap(ex)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/tco_method/block_extractor.rb', line 11

def source
  @source
end