Module: Nuggets::File::SubMixin
- Included in:
- File
- Defined in:
- lib/nuggets/file/sub_mixin.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#gsub(name, *args) ⇒ Object
call-seq: File.gsub(name, *args, &block) => aString.
-
#gsub!(name, *args) ⇒ Object
call-seq: File.gsub!(name, *args, &block) => aString or
nil. -
#sub(name, *args) ⇒ Object
call-seq: File.sub(name, *args, &block) => aString.
-
#sub!(name, *args) ⇒ Object
call-seq: File.sub!(name, *args, &block) => aString or
nil.
Class Method Details
.extended(base) ⇒ Object
34 35 36 |
# File 'lib/nuggets/file/sub_mixin.rb', line 34 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.
71 72 73 74 75 |
# File 'lib/nuggets/file/sub_mixin.rb', line 71 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.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/nuggets/file/sub_mixin.rb', line 83 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.
43 44 45 46 47 |
# File 'lib/nuggets/file/sub_mixin.rb', line 43 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.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nuggets/file/sub_mixin.rb', line 55 def sub!(name, *args) res = nil replace(name) { |content| res = content.sub!(*args, &block_given? ? ::Proc.new : nil) content } res end |