Pasting strings into irb

Discussion in 'Ruby' started by Ben, Mar 3, 2005.

  1. Ben

    Ben Guest

    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
     
    Ben, Mar 3, 2005
    #1
    1. Advertising

  2. Ben

    mike leonard Guest

    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.
     
    mike leonard, Mar 3, 2005
    #2
    1. Advertising

  3. Ben

    Csaba Henk Guest

    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
     
    Csaba Henk, Mar 3, 2005
    #3
  4. 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
     
    Martin DeMello, Mar 3, 2005
    #4
  5. Ben

    Ben Guest

    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.
     
    Ben, Mar 3, 2005
    #5
  6. "Ben" <> schrieb im Newsbeitrag
    news:...
    > 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
     
    Robert Klemme, Mar 3, 2005
    #6
  7. Ben

    Ben Guest

    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
     
    Ben, Mar 3, 2005
    #7
  8. "Ben" <> schrieb im Newsbeitrag
    news:...
    > 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
     
    Robert Klemme, Mar 4, 2005
    #8
  9. 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
     
    Martin DeMello, Mar 8, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?=

    pasting xml data into an excel template

    =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?=, Aug 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    677
  2. Anguel Stankov

    Pasting a file into a Java String

    Anguel Stankov, May 11, 2004, in forum: Java
    Replies:
    16
    Views:
    777
    Roedy Green
    May 14, 2004
  3. Marc Van Laer
    Replies:
    0
    Views:
    423
    Marc Van Laer
    Apr 11, 2005
  4. Wladimir Borsov
    Replies:
    0
    Views:
    372
    Wladimir Borsov
    Aug 28, 2003
  5. benny
    Replies:
    1
    Views:
    146
    Mark Hubbart
    May 26, 2005
Loading...

Share This Page