Gavin Kistner
10/13/2006 8:40:00 PM
From: Gavin Kistner
> Sent: Friday, October 13, 2006 2:35 PM
> To: ruby-talk ML
> Subject: Re: file_put_contents analog?
>
> From: Joe Ruby MUDCRAP-CE
> > PHP has a function file_put_contents(file, stuff) -- is there any
> > similar single command in Ruby?
>
> def file_put_contents( name, *contents )
> File.open( name, "w+" { |file|
> contents.each{ |item|
> file << item
> }
> }
> end
Er, missing a paren there. Also, if you want append vs. wipe-and-write,
use 'a':
def file_put_contents( name, *contents )
File.open( name, "a" ){ |file|
contents.each{ |item|
file << item
}
}
end