# Creating a StringIO object

**URL:** <https://www.ruby-forum.com/t/creating-a-stringio-object/116202>\
**Category:** Ruby\
**Created:** [October 3, 2007, 12:37pm UTC](https://www.ruby-forum.com/t/creating-a-stringio-object/116202 "2007-10-03T12:37:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [October 3, 2007, 12:37pm UTC](https://www.ruby-forum.com/t/creating-a-stringio-object/116202/1 "2007-10-03T12:37:00Z")

</div>

Hi all, can any body tell me how to create a StringIO object from an  
existing string object.

my code str = StringIO.new results an error saying that  
“uninitialized constant StringIO(NameError)”

What i sthe problem with the above code

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [October 3, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/creating-a-stringio-object/116202/2 "2007-10-03T13:14:24Z")

</div>

> my code str = StringIO.new results an error saying that  
> “uninitialized constant StringIO(NameError)”
> 
> ## What i sthe problem with the above code
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You need to load the StringIO library:

irb(main):001:0\> str = StringIO.new  
NameError: uninitialized constant StringIO  
from (irb):1  
irb(main):002:0\> require ‘stringio’  
=\> true  
irb(main):003:0\> str = StringIO.new  
=\> #StringIO:0xb7ce6c6c  
irb(main):004:0\>

HTH,

Felix

---

<div class="post-metadata">

**Author:** ![learningruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6bbea6/32.png) [@learningruby](https://www.ruby-forum.com/u/learningruby)\
**Post date:** [October 4, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/creating-a-stringio-object/116202/3 "2007-10-04T20:50:48Z")

</div>

On Oct 3, 5:37 am, Venkat B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all, can any body tell me how to create a StringIO object from an  
> existing string object.
> 
> my code str = StringIO.new results an error saying that  
> “uninitialized constant StringIO(NameError)”
> 
> ## What i sthe problem with the above code
> 
> Posted viahttp://www.ruby-forum.com/.

You have to require the stringio library  
require ‘stringio’
