module Nuggets::File::SubMixin

Public Class Methods

extended(base) click to toggle source
   # File lib/nuggets/file/sub_mixin.rb
33 def self.extended(base)
34   base.extend Nuggets::File::ReplaceMixin
35 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
70 def gsub(name, *args, &block)
71   content = read(name)
72   content.gsub!(*args, &block)
73   content
74 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
82 def gsub!(name, *args, &block)
83   res = nil
84 
85   replace(name) { |content|
86     res = content.gsub!(*args, &block)
87     content
88   }
89 
90   res
91 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
42 def sub(name, *args, &block)
43   content = read(name)
44   content.sub!(*args, &block)
45   content
46 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
54 def sub!(name, *args, &block)
55   res = nil
56 
57   replace(name) { |content|
58     res = content.sub!(*args, &block)
59     content
60   }
61 
62   res
63 end