Class: Spoom::Source::Insert
Instance Attribute Summary collapse
- #position ⇒ Object readonly
- #text ⇒ Object readonly
Instance Method Summary collapse
- #apply(bytes) ⇒ Object
-
#initialize(position, text) ⇒ Insert
constructor
A new instance of Insert.
- #range ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(position, text) ⇒ Insert
Returns a new instance of Insert.
47 48 49 50 51 52 |
# File 'lib/spoom/source/rewriter.rb', line 47 def initialize(position, text) super() @position = position @text = text end |
Instance Attribute Details
#position ⇒ Object (readonly)
41 42 43 |
# File 'lib/spoom/source/rewriter.rb', line 41 def position @position end |
#text ⇒ Object (readonly)
44 45 46 |
# File 'lib/spoom/source/rewriter.rb', line 44 def text @text end |
Instance Method Details
#apply(bytes) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/spoom/source/rewriter.rb', line 56 def apply(bytes) raise PositionError, "Position is out of bounds" if position < 0 || position > bytes.size bytes #: untyped .insert(position, *text.bytes) end |
#range ⇒ Object
65 66 67 |
# File 'lib/spoom/source/rewriter.rb', line 65 def range [position, position] end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/spoom/source/rewriter.rb', line 71 def to_s "Insert `#{text}` at #{position}" end |