module Nuggets::File::SubMixin

Public Class Methods

extended(base) click to toggle source
# File lib/nuggets/file/sub_mixin.rb, line 33
def self.extended(base)
  base.extend Nuggets::File::ReplaceMixin
end

Public Instance Methods

gsub(name, *args, &block) → aString click to toggle source

Calls String#gsub! on file name's contents with args and (optional) block and returns the new content.

# File lib/nuggets/file/sub_mixin.rb, line 70
def gsub(name, *args)
  content = read(name)
  content.gsub!(*args, &block_given? ? ::Proc.new : nil)
  content
end
gsub!(name, *args, &block) → aString or +nil+ click to toggle source

Calls String#gsub! on file name's contents with args and (optional) block and replaces the file with the new content. Returns the result of the String#gsub! call.

# File lib/nuggets/file/sub_mixin.rb, line 82
def gsub!(name, *args)
  res = nil

  replace(name) { |content|
    res = content.gsub!(*args, &block_given? ? ::Proc.new : nil)
    content
  }

  res
end
sub(name, *args, &block) → aString click to toggle source

Calls String#sub! on file name's contents with args and (optional) block and returns the new content.

# File lib/nuggets/file/sub_mixin.rb, line 42
def sub(name, *args)
  content = read(name)
  content.sub!(*args, &block_given? ? ::Proc.new : nil)
  content
end
sub!(name, *args, &block) → aString or +nil+ click to toggle source

Calls String#sub! on file name's contents with args and (optional) block and replaces the file with the new content. Returns the result of the String#sub! call.

# File lib/nuggets/file/sub_mixin.rb, line 54
def sub!(name, *args)
  res = nil

  replace(name) { |content|
    res = content.sub!(*args, &block_given? ? ::Proc.new : nil)
    content
  }

  res
end