[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pasting strings into irb

Ben

3/3/2005 4:26:00 AM

I would like to use ruby to do interesting manipulations of strings.
Ideally, I'd be able to copy multiple lines of text from a text editor,
paste those lines of text into irb (as a string), manipulate that
string, copy the result, and then paste it back into the original
editor. I know that sounds like a lot of work, but the manipulations I
want to do aren't trivial enough to do with the standard find/replace
features of most editors.

For instance, (this is kind of contrived) but say I wanted to take any
answers to this post, and make the first and last letter of each word
uppercase or something and then save that text in an email.

Is there a way to paste multiple lines of text into irb and save them
as a single string value? I tried using 'here documents' but that
didn't work.

By the way, I'm using FXirb since I'm runnign windows and cmd.exe isn't
great about copying/pasting in general. Thanks.

Ben

8 Answers

mikeleonard

3/3/2005 4:33:00 AM

0

Why not save all the text to a file and then use File.read to read the
file into a string and do your manipulations from there? I did that
recently when I wanted to massage an HTML table into a tab-delimited
plain text file.

Csaba Henk

3/3/2005 5:42:00 AM

0

On 2005-03-03, Ben <bhbrinckerhoff@wustl.edu> wrote:
> Is there a way to paste multiple lines of text into irb and save them
> as a single string value? I tried using 'here documents' but that
> didn't work.

How can it be? For me they do the job without whining...

Csaba

Martin DeMello

3/3/2005 7:21:00 AM

0

Ben <bhbrinckerhoff@wustl.edu> wrote:
>
> Is there a way to paste multiple lines of text into irb and save them
> as a single string value? I tried using 'here documents' but that
> didn't work.
>
> By the way, I'm using FXirb since I'm runnign windows and cmd.exe isn't
> great about copying/pasting in general. Thanks.

That seems to be a bug in fxirb. Thanks for the report - I'll try to get
it fixed asap.

martin

Ben

3/3/2005 9:17:00 AM

0


mike leonard wrote:
> Why not save all the text to a file and then use File.read to read
the
> file into a string and do your manipulations from there? I did that
> recently when I wanted to massage an HTML table into a tab-delimited
> plain text file.

That's certainly a good idea, and I did try that for awhile. The
problem is that I'm working with these strings a whole lot, so I'd like
to cut down the number of steps to the bare minimum.

Thanks for the idea though.

Robert Klemme

3/3/2005 10:43:00 AM

0


"Ben" <bhbrinckerhoff@wustl.edu> schrieb im Newsbeitrag
news:1109823967.917281.249900@f14g2000cwb.googlegroups.com...
> I would like to use ruby to do interesting manipulations of strings.
> Ideally, I'd be able to copy multiple lines of text from a text editor,
> paste those lines of text into irb (as a string), manipulate that
> string, copy the result, and then paste it back into the original
> editor. I know that sounds like a lot of work, but the manipulations I
> want to do aren't trivial enough to do with the standard find/replace
> features of most editors.
>
> For instance, (this is kind of contrived) but say I wanted to take any
> answers to this post, and make the first and last letter of each word
> uppercase or something and then save that text in an email.
>
> Is there a way to paste multiple lines of text into irb and save them
> as a single string value? I tried using 'here documents' but that
> didn't work.
>
> By the way, I'm using FXirb since I'm runnign windows and cmd.exe isn't
> great about copying/pasting in general. Thanks.
>
> Ben

You can use here documents for that:

10:06:42 [source]: irbs
>> s=<<EOS
I would like to use ruby to do interesting manipulations of strings.
Ideally, I'd be able to copy multiple lines of text from a text editor,
paste those lines of text into irb (as a string), manipulate that
string, copy the result, and then paste it back into the original
editor. I know that sounds like a lot of work, but the manipulations I
want to do aren't trivial enough to do with the standard find/replace
features of most editors.
EOS
=> "I would like to use ruby to do interesting manipulations of
strings.\nIdeally, I'd be able to copy multiple lines of text from a text
editor,\npas
te those lines of text into irb (as a string), manipulate that\nstring,
copy the result, and then paste it back into the original\neditor. I know
that
sounds like a lot of work, but the manipulations I\nwant to do aren't
trivial enough to do with the standard find/replace\nfeatures of most
editors.n"
>> s.tr 'A-Z', 'a-z'
=> "i would like to use ruby to do interesting manipulations of
strings.\nideally, i'd be able to copy multiple lines of text from a text
editor,\npas
te those lines of text into irb (as a string), manipulate that\nstring,
copy the result, and then paste it back into the original\neditor. i know
that
sounds like a lot of work, but the manipulations i\nwant to do aren't
trivial enough to do with the standard find/replace\nfeatures of most
editors.n"
>> exit
11:42:09 [source]:

Kind regards

robert

Ben

3/3/2005 10:00:00 PM

0

Robert,

Thanks for the idea, although I tried that and it did not work. This
seems to be a problem with FXirb as Martin indicated. Thanks, all!

Ben

Robert Klemme

3/4/2005 9:13:00 AM

0


"Ben" <bhbrinckerhoff@wustl.edu> schrieb im Newsbeitrag
news:1109887176.435481.9860@g14g2000cwa.googlegroups.com...
> Robert,
>
> Thanks for the idea, although I tried that and it did not work. This
> seems to be a problem with FXirb as Martin indicated. Thanks, all!

Something that works on cygwin but not *nix? Whoa...
;-)

robert

Martin DeMello

3/8/2005 7:26:00 PM

0

Ben <bhbrinckerhoff@wustl.edu> wrote:
>
> Is there a way to paste multiple lines of text into irb and save them
> as a single string value? I tried using 'here documents' but that
> didn't work.
>
> By the way, I'm using FXirb since I'm runnign windows and cmd.exe isn't
> great about copying/pasting in general. Thanks.

There's a somewhat kludgy fix for this in CVS now (works but prints
extraneous prompts to the screen), but it looks like I'm going to have
to overhaul the input/output system to fully fix this and one or two
other bugs.

martin

Patch follows:

--- fxirb.rb.old 2005-03-09 00:50:46.000000000 +0530
+++ fxirb.rb 2005-03-09 00:50:08.000000000 +0530
@@ -276,9 +276,11 @@

def processCommandLine(cmd)
#write("[#{cmd}]")
- @input[1].puts cmd
- @inputAdded = true
- @irb.run
+ cmd.split(/\n/).each {|i|
+ @input[1].puts i
+ @inputAdded = true
+ @irb.run
+ }
end