Module: AdjustN

Defined in:
lib/adjustn/newlinechar.rb,
lib/adjustn/version.rb,
lib/adjustn/singleton_class.rb

Overview

Copyright © 2012 Kenichi Kamiya

Defined Under Namespace

Modules: NewlineChar

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.run(after_code, *pathnames) ⇒ void

This method returns an undefined value.

Parameters:

  • after_code (Symbol, String)

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/adjustn/singleton_class.rb', line 8

def run(after_code, *pathnames)
  raise ArgumentError unless pathnames.length >= 1

  before, after = *pair_for(after_code)

  pathnames.each do |pathname|
    source = File.binread(pathname)

    if output = gsub_for!(source, before, after)
      File.open(pathname, 'wb') do |f|
        f << output
      end
    else
      $stderr.puts %Q!Already adjusted the file "#{pathname}"!
    end
  end
end