Class: TCOMethod::BlockExtractor
- Inherits:
-
Object
- Object
- TCOMethod::BlockExtractor
- 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
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(block) ⇒ BlockExtractor
constructor
A new instance of BlockExtractor.
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
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/tco_method/block_extractor.rb', line 11 def source @source end |