Forum: Ruby rio-editing on-the-fly

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B7f73e9f9d35be6a44b15f603f2910d4?d=identicon&s=25 wybo (Guest)
on 2005-12-01 21:42
(Received via mailing list)
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?
Bfcc9047bea80035a936648dc1912ec4?d=identicon&s=25 gsinclair (Guest)
on 2005-12-02 08:15
(Received via mailing list)
Wybo Dekker 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
B7f73e9f9d35be6a44b15f603f2910d4?d=identicon&s=25 wybo (Guest)
on 2005-12-02 09:44
(Received via mailing list)
On Fri, 2 Dec 2005, Gavin Sinclair 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))
Bfcc9047bea80035a936648dc1912ec4?d=identicon&s=25 gsinclair (Guest)
on 2005-12-02 13:44
(Received via mailing list)
Wybo Dekker 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
This topic is locked and can not be replied to.