lib/sugar-high/file.rb in sugar-high-0.2.2 vs lib/sugar-high/file.rb in sugar-high-0.2.4
- old
+ new
@@ -33,10 +33,14 @@
def self.append path, content=nil, &block
File.open(path, 'w+') do |f|
f.puts content ||= yield
end
end
+
+ def self.remove_from file_name, content, &block
+ replace_content_from file_name, :content => content, :with => '', &block
+ end
# replaces content found at replacement_expr with content resulting from yielding block
# File.replace_content_from 'myfile.txt', where => /HelloWorld/, with => 'GoodBye'
def self.replace_content_from file_name, options = {}, &block
replacement_expr = options[:where] || options[:content]
@@ -148,10 +152,10 @@
def self.content options = {}, *args, &block
case args.first
when String
args.first
when Hash
- options[:content] || yield if block
+ options[:content] || (yield if block)
else
return yield if block
raise ArgumentError, "You must supply content to insert, either as a String before the options hash, a :content option or a block"
end
end