# File\_put\_contents analog?

**URL:** <https://www.ruby-forum.com/t/file-put-contents-analog/72062>\
**Category:** Ruby\
**Created:** [October 13, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/file-put-contents-analog/72062 "2006-10-13T22:27:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [October 13, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/file-put-contents-analog/72062/1 "2006-10-13T22:27:06Z")

</div>

PHP has a function file\_put\_contents(file, stuff) – is there any  
similar single command in Ruby?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [October 13, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/file-put-contents-analog/72062/2 "2006-10-13T22:33:40Z")

</div>

On 10/13/06, Joe R. MUDCRAP-CE [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> PHP has a function file\_put\_contents(file, stuff) – is there any  
> similar single command in Ruby?

file.puts(stuff)

If you don’t already have the file in question open for writing:  
File.open(‘some\_file.txt’,‘w’) {|file| file.puts stuff}

File gets most of its useful functionality from its parent, IO:  
[http://www.rubycentral.com/book/ref\_c\_io.html](http://www.rubycentral.com/book/ref_c_io.html)
