I am totally new to programming so this may sound stupid, but I would
appreciate help.
I am following along in the the Simply Rails 2 book and I am entering
classes etc. into the irb shell in the ruby console window. The problem
I am having is that sometimes I enter the wrong command and I can’t
figure out how to exit the irb shell. I have tried typing “exit” and
that works sometimes, but sometimes it doesn’t. The issue arose once
after I hit the Tab key and the other time i don’t think i pressed
anything out of the ordinary.
Please see screenshot for clarification.
Can someone please help?
Thanks!
Sometimes I open a parentheses without closing it, or a DO without an
END, or a { without a }… Once you get the hang of Ruby’s pretty loose
syntax, you’ll also realize you forgot to close something. That’s not
what you did in the screenshot, but I’m warning you for next time. I
forget to do that all the time.
If all else fails, I hit CTRL+C, but I don’t know if that causes
problems. Someone have a better understanding?
Clinton D. Judy wrote:
Sometimes I open a parentheses without closing it, or a DO without an
END, or a { without a }… Once you get the hang of Ruby’s pretty loose
syntax, you’ll also realize you forgot to close something. That’s not
what you did in the screenshot, but I’m warning you for next time. I
forget to do that all the time.
If all else fails, I hit CTRL+C, but I don’t know if that causes
problems. Someone have a better understanding?
Your exit is not really executed, because as you see, you are without
some nesting (the 3 in 009:3> tells you you’re in sine three things,
like three classes or methods or something). You must first go out of
all things you’re in by typing end in each line (or closing brackets).
Usually when you do a mistake, just type end and press enter until you
see the prompt ends with NNN:0> again (there might be some error message
too, just ignore it), and then your exit or anything else will work.
But for testing, just write a separate program! You won’t have to repeat
everything in case of a mistake every time. Here is something about
writing separate programs:
TPR.
Thomas B. wrote:
Clinton D. Judy wrote:
Sometimes I open a parentheses without closing it, or a DO without an
END, or a { without a }… Once you get the hang of Ruby’s pretty loose
syntax, you’ll also realize you forgot to close something. That’s not
what you did in the screenshot, but I’m warning you for next time. I
forget to do that all the time.
If all else fails, I hit CTRL+C, but I don’t know if that causes
problems. Someone have a better understanding?
Your exit is not really executed, because as you see, you are without
some nesting (the 3 in 009:3> tells you you’re in sine three things,
like three classes or methods or something). You must first go out of
all things you’re in by typing end in each line (or closing brackets).
Usually when you do a mistake, just type end and press enter until you
see the prompt ends with NNN:0> again (there might be some error message
too, just ignore it), and then your exit or anything else will work.
But for testing, just write a separate program! You won’t have to repeat
everything in case of a mistake every time. Here is something about
writing separate programs:
Ruby (Al2O3::Cr)
TPR.
The problem was that I didn’t type end. I feel very stupid now. Thanks
for the help all!
Also found that CTRL+D works. Is this a coincidence that CTRL+C and
CTRL+D both work?
Cheers!
Scott
On Thu, Sep 18, 2008 at 12:27:07AM +0900, Scott Harper wrote:
Please see screenshot for clarification.
It looks like you typed irb twice. Once to get into the shell, and once
while in the
shell. I see though that you are using windows, and I have no idea how
irb works on there, but I would have thought it was similar.
npowell@delilah ~ $ irb
irb
exit
=> #<IRB::Irb: @context=#IRB::Context:0xb7a2d840,
@signal_status=:IN_EVAL, @scanner=#RubyLex:0xb7a2d4a8>
exit
npowell@delilah ~ $
–
nathan
nathan_at_nathanpowell_dot_org
Another flaw in the human character is that everybody wants to build
and nobody wants to do maintenance.
~ Kurt Vonnegut
Scott Harper wrote:
Can someone please help?
Thanks!
Attachments:
http://www.ruby-forum.com/attachment/2706/irb_shell_exit.JPG
Note that “exit” is just another ruby function that simply exits the
running program (irb in this case) rather than something like an irb
“metacommand”.
It seems that apart from typing irb twice in your session you forgot to
close your function and class definitions with “end”, thus ruby is
still waiting for you to finish them before the definition (and any
exit call outside of a function definition) gets evaluated as a
whole. An exit call inside a method definition of a class will only be
evaluated if that method is actually being called.
So, if you need to bail out of irb, either call exit while not being
inside a class or method def, or hit CTRL-D (on linux) or CTRL-Z (on
windows). This sends an EOT control sequence which will prematurely
close irb.
Henning