# Rio-editing on-the-fly

**URL:** <https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262>\
**Category:** Ruby\
**Created:** [December 1, 2005, 9:42pm UTC](https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262 "2005-12-01T21:42:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@wybo](https://www.ruby-forum.com/u/wybo)\
**Post date:** [December 1, 2005, 9:42pm UTC](https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262/1 "2005-12-01T21:42:42Z")

</div>

according to the rio-docs I would expect it to be possible to edit a  
file  
on-the-fly; for example, I tried to make a copy of /etc/passwd with my  
own  
name (wybo) replaced with XXXX:

rio(’/etc/passwd’).gsub(/wybo/,‘XXXX’) \> rio(‘new’)

but the resulting file “new” is an exact copy of /etc/passwd.  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![wybo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@wybo](https://www.ruby-forum.com/u/wybo)\
**Post date:** [December 2, 2005, 8:15am UTC](https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262/2 "2005-12-02T08:15:21Z")

</div>

Wybo D. wrote:

> according to the rio-docs I would expect it to be possible to edit a file  
> on-the-fly; for example, I tried to make a copy of /etc/passwd with my own  
> name (wybo) replaced with XXXX:
> 
> rio(’/etc/passwd’).gsub(/wybo/,‘XXXX’) \> rio(‘new’)
> 
> but the resulting file “new” is an exact copy of /etc/passwd.  
> What am I doing wrong?

You’re not reading the file. Try

rio(’/etc/passwd’).read.gsub(/wybo/,‘XXXX’) \> rio(‘new’)

Perhaps there’s a better suggestion?

Gavin

---

<div class="post-metadata">

**Author:** ![wybo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@wybo](https://www.ruby-forum.com/u/wybo)\
**Post date:** [December 2, 2005, 1:44pm UTC](https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262/3 "2005-12-02T13:44:45Z")

</div>

Wybo D. wrote:

> Create a new Rio referencing the result of applying String#sub to the  
> value returned by Rio#to\_s. So:

Now you’ve just gotta double check what Rio#to\_s does 🙂

Gavin

---

<div class="post-metadata">

**Author:** ![wybo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/cc9497/32.png) [@wybo](https://www.ruby-forum.com/u/wybo)\
**Post date:** [December 2, 2005, 9:44am UTC](https://www.ruby-forum.com/t/rio-editing-on-the-fly/49262/4 "2005-12-02T09:44:54Z")

</div>

On Fri, 2 Dec 2005, Gavin S. wrote:

> You’re not reading the file. Try
> 
> rio(’/etc/passwd’).read.gsub(/wybo/,‘XXXX’) \> rio(‘new’)

that helped indeed, thanks, but is it not in contradiction to rio’s  
description of sub?:

sub(re,string)

Create a new Rio referencing the result of applying String#sub to the  
value returned by Rio#to\_s. So:

ario.sub(re,string)

is equivelent to

rio(ario.to\_s.sub(re,string))
