irb question - variable definitions when calling irb from a script problem

Discussion in 'Ruby' started by Nuralanur@aol.com, Oct 26, 2005.

  1. Guest

    -------------------------------1130353930
    Content-Type: text/plain; charset="US-ASCII"
    Content-Transfer-Encoding: 7bit


    Dear all,

    I have written a script containing some quite lengthy definitions of an
    array full
    of parameters and methods for it. This works fine, but now I'd like
    to change some value in the array and use some method of the script on it.
    I do not know which value of the parameters will be changed nor
    really, which method out of several will be used in advance, so I'd
    like to use irb to do that interactively.
    I can call irb from the script, but then it does not remember that
    in the script, I had defined array[4544]="my nice parameter value"
    anymore, same thing if I start irb directly and use require "myscript.rb".

    Is there some workaround that permits to make a variable definition in a
    script "interactively global" ?

    Best regards,

    Axel


    -------------------------------1130353930--
    , Oct 26, 2005
    #1
    1. Advertising

  2. Re: irb question - variable definitions when calling irb from a scriptproblem

    wrote:

    > I can call irb from the script, but then it does not remember that
    > in the script, I had defined array[4544]="my nice parameter value"
    > anymore, same thing if I start irb directly and use require "myscript.rb".


    By default IRB.start starts the IRB instance in its new custom context
    that will not have local variables from your context defined.

    In ruby-breakpoint I'm using this overloaded version to specify a context:

    > module IRB # :nodoc:
    > class << self; remove_method :start; end
    > def self.start(ap_path = nil, main_context = nil, workspace = nil)
    > $0 = File::basename(ap_path, ".rb") if ap_path
    >
    > # suppress some warnings about redefined constants
    > old_verbose, $VERBOSE = $VERBOSE, nil
    > IRB.setup(ap_path)
    > $VERBOSE = old_verbose
    >
    > if @CONF[:SCRIPT] then
    > irb = Irb.new(main_context, @CONF[:SCRIPT])
    > else
    > irb = Irb.new(main_context)
    > end
    >
    > if workspace then
    > irb.context.workspace = workspace
    > end
    >
    > @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
    > @CONF[:MAIN_CONTEXT] = irb.context
    >
    > old_sigint = trap("SIGINT") do
    > begin
    > irb.signal_handle
    > rescue RubyLex::TerminateLineInput
    > # ignored
    > end
    > end
    >
    > catch:)IRB_EXIT) do
    > irb.eval_input
    > end
    > ensure
    > trap("SIGINT", old_sigint)
    > end
    > end


    It's used as IRB.start(nil, binding).
    Florian Groß, Oct 26, 2005
    #2
    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. Patrice
    Replies:
    1
    Views:
    1,628
    =?Utf-8?B?REZyYW5rbHlu?=
    May 13, 2004
  2. raphfrk

    question on variable definitions

    raphfrk, Mar 2, 2007, in forum: C Programming
    Replies:
    23
    Views:
    684
    Bill Pursell
    Mar 3, 2007
  3. Jaco Naude
    Replies:
    1
    Views:
    348
    Alf P. Steinbach
    Jul 3, 2009
  4. Sam Stephenson
    Replies:
    1
    Views:
    213
    Andrew Walrond
    Jun 18, 2005
  5. anne001
    Replies:
    1
    Views:
    255
    anne001
    Jun 27, 2006
Loading...

Share This Page