Module: Nuggets::File::SubMixin

Included in:
File
Defined in:
lib/nuggets/file/sub_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



33
34
35
# File 'lib/nuggets/file/sub_mixin.rb', line 33

def self.extended(base)
  base.extend Nuggets::File::ReplaceMixin
end

Instance Method Details

#gsub(name, *args) ⇒ Object

call-seq:

File.gsub(name, *args, &block) => aString

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



70
71
72
73
74
# 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) ⇒ Object

call-seq:

File.gsub!(name, *args, &block) => aString or +nil+

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.



82
83
84
85
86
87
88
89
90
91
# 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) ⇒ Object

call-seq:

File.sub(name, *args, &block) => aString

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



42
43
44
45
46
# 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) ⇒ Object

call-seq:

File.sub!(name, *args, &block) => aString or +nil+

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.



54
55
56
57
58
59
60
61
62
63
# 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