Module: AdjustN

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

Overview

Copyright (C) 2012 Kenichi Kamiya

Defined Under Namespace

Modules: NewlineChar

Constant Summary collapse

VERSION =
'0.0.3'.freeze

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)

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

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 %!Already adjuted the file "#{pathname}"!
    end
  end
end