Pasting strings into irb

B

Ben

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
 
M

mike leonard

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.
 
C

Csaba Henk

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
 
M

Martin DeMello

Ben said:
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
 
B

Ben

mike said:
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.
 
R

Robert Klemme

Ben said:
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]: irbsI 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"=> "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"11:42:09 [source]:

Kind regards

robert
 
B

Ben

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
 
R

Robert Klemme

Ben said:
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
 
M

Martin DeMello

Ben said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top