irb: Is it possible to automatically create a subsession on startup?

Discussion in 'Ruby' started by wfisk, Oct 28, 2008.

  1. wfisk

    wfisk Guest

    In irb I can create an object and then create a new subsession with
    that object as the context.
    For example in irb I can type
    $psauto = PSAuto::Automator.new
    irb $psauto

    Now I can call all the methids of $psauto without having to type the
    '$psauto' each time.

    Is it possible to put these two lines into an irb config file so that
    I do not have to type them every time I start irb?
    wfisk, Oct 28, 2008
    #1
    1. Advertising

  2. wfisk

    Roger Pack Guest


    > Is it possible to put these two lines into an irb config file so that
    > I do not have to type them every time I start irb?


    I believe there's a ~/.irbrc
    -=R
    --
    Posted via http://www.ruby-forum.com/.
    Roger Pack, Oct 28, 2008
    #2
    1. Advertising

  3. wfisk

    William Fisk Guest

    yes I am using .irbrc, but it doesn't work when you pur
    'irb $psauto' in it. At least it doesn't work for me

    --
    Posted via http://www.ruby-forum.com/.
    William Fisk, Oct 28, 2008
    #3
  4. William Fisk wrote:
    > yes I am using .irbrc, but it doesn't work when you pur
    > 'irb $psauto' in it. At least it doesn't work for me


    Try this in .irbrc:

    module IRB
    def IRB.start_session(*args)
    unless $irb
    IRB.setup nil
    end

    workspace = WorkSpace.new(*args)

    if @CONF[:SCRIPT] ## normally, set by parse_opts
    $irb = Irb.new(workspace, @CONF[:SCRIPT])
    else
    $irb = Irb.new(workspace)
    end

    @CONF[:IRB_RC].call($irb.context) if @CONF[:IRB_RC]
    @CONF[:MAIN_CONTEXT] = $irb.context

    trap 'INT' do
    $irb.signal_handle
    end

    custom_configuration if defined?(IRB.custom_configuration)

    catch :IRB_EXIT do
    $irb.eval_input
    end
    end
    end

    x = Object.new
    puts "\nStarted irb shell for x"
    IRB.start_session(x)

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Oct 28, 2008
    #4
  5. wfisk

    William Fisk Guest

    Joel,

    Thanks for that. Unfortunately it doesn't work for me.
    I get lots of errors like the following

    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant UnrecognizedSwitch
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant NotImplementedError
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant CantReturnToNormalMode
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant IllegalParameter
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant IrbAlreadyDead
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant IrbSwitchedToCurrentThread
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant NoSuchJob
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant CantShiftToMultiIrbMode
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    warning: already initialized constant CantChangeBinding

    However, I googled "IRB.start_session" and found some other interesting
    post and replies (all by you I think!); and I can see other things are
    possible.
    I'm going to look at this again tomorrow.

    Thanks

    William
    --
    Posted via http://www.ruby-forum.com/.
    William Fisk, Oct 28, 2008
    #5
  6. William Fisk wrote:
    > Joel,
    >
    > Thanks for that. Unfortunately it doesn't work for me.
    > I get lots of errors like the following
    >
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant UnrecognizedSwitch
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant NotImplementedError
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant CantReturnToNormalMode
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant IllegalParameter
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant IrbAlreadyDead
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant IrbSwitchedToCurrentThread
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant NoSuchJob
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant CantShiftToMultiIrbMode
    > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/e2mmap.rb:152:
    > warning: already initialized constant CantChangeBinding
    >
    > However, I googled "IRB.start_session" and found some other interesting
    > post and replies (all by you I think!); and I can see other things are
    > possible.
    > I'm going to look at this again tomorrow.
    >
    > Thanks
    >
    > William


    Sorry, cut-and-paste error :(

    Removing the

    IRB.setup nil

    call should help. Here's the code for .irbrc:

    module IRB
    def IRB.start_session(*args)
    workspace = WorkSpace.new(*args)

    if @CONF[:SCRIPT] ## normally, set by parse_opts
    $irb = Irb.new(workspace, @CONF[:SCRIPT])
    else
    $irb = Irb.new(workspace)
    end

    @CONF[:IRB_RC].call($irb.context) if @CONF[:IRB_RC]
    @CONF[:MAIN_CONTEXT] = $irb.context

    trap 'INT' do
    $irb.signal_handle
    end

    custom_configuration if defined?(IRB.custom_configuration)

    catch :IRB_EXIT do
    $irb.eval_input
    end
    end
    end

    x = Object.new
    puts "\nStarted irb shell for x"
    IRB.start_session(x)


    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Oct 28, 2008
    #6
  7. wfisk

    William Fisk Guest

    Hey Joel,

    Thanks man, that works. I did start looking at the IRB code but it was
    too complicated for me.

    Now time for bed.


    --
    Posted via http://www.ruby-forum.com/.
    William Fisk, Oct 28, 2008
    #7
    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. Sam Stephenson
    Replies:
    1
    Views:
    210
    Andrew Walrond
    Jun 18, 2005
  2. Replies:
    1
    Views:
    145
    Florian GroƟ
    Oct 26, 2005
  3. Replies:
    4
    Views:
    92
  4. Pravin Kumar

    irb error on startup

    Pravin Kumar, Aug 15, 2008, in forum: Ruby
    Replies:
    3
    Views:
    290
    Steve Lewis
    Aug 27, 2008
  5. Chris Dew

    [ANN] SubSession (tab-specific sessions)

    Chris Dew, Jun 13, 2011, in forum: Javascript
    Replies:
    0
    Views:
    103
    Chris Dew
    Jun 13, 2011
Loading...

Share This Page