Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Pasting strings into irb

Reply
Thread Tools

Pasting strings into irb

 
 
Ben
Guest
Posts: n/a
 
      03-03-2005
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

 
Reply With Quote
 
 
 
 
mike leonard
Guest
Posts: n/a
 
      03-03-2005
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.

 
Reply With Quote
 
 
 
 
Csaba Henk
Guest
Posts: n/a
 
      03-03-2005
On 2005-03-03, Ben <> 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
 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      03-03-2005
Ben <> 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
 
Reply With Quote
 
Ben
Guest
Posts: n/a
 
      03-03-2005

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.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-03-2005

"Ben" <> schrieb im Newsbeitrag
news: oups.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

 
Reply With Quote
 
Ben
Guest
Posts: n/a
 
      03-03-2005
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

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      03-04-2005

"Ben" <> schrieb im Newsbeitrag
news: ps.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

 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      03-08-2005
Ben <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
irb require ... where does irb look? what path? anne001 Ruby 1 06-27-2006 12:07 PM
irb question - variable definitions when calling irb from a script problem Nuralanur@aol.com Ruby 1 10-26-2005 09:13 PM
pasting xml data into an excel template =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?= ASP .Net 1 08-24-2005 07:50 PM
[ANN] irb-history 1.0.0: Persistent, shared Readline history for IRB Sam Stephenson Ruby 1 06-18-2005 08:56 AM
Pasting code with tab indentation to irb benny Ruby 1 05-26-2005 05:46 PM



Advertisments