Class: PryToggle::Service
- Inherits:
-
Object
- Object
- PryToggle::Service
- Defined in:
- lib/pry_toggle/service.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pry_toggle/service.rb', line 6 def execute fail '' unless origin_path tempfile = File.open(tmp_file_path, 'w') f = File.open(abs_file_path, 'r') f.each.with_index(1) do |line, i| tempfile << line if i == line_num tempfile << str end end f.close tempfile.close FileUtils.mv(tmp_file_path, abs_file_path) end |