plhn
plhn

Reputation: 5263

irb does not print anything

I'm a newbie at ruby.
While I am using irb, something happens.(Nothings are printed)
Does anyone have any advise about this?
I cannot know even what search keyword would be OK for this situation.
(maybe an environment-specific problem? How do you think?)

irb(main):010:0> a = [3,2,1]
=> [3, 2, 1]
irb(main):011:0> a.each
=> #<Enumerable::Enumerator:0x7f413a20d668>
irb(main):012:0> a.each{|x| print x}
321=> [3, 2, 1]
irb(main):013:0> a.each do |x| print x end
321=> [3, 2, 1]
irb(main):014:0> 1.to 9
NoMethodError: undefined method `to' for 1:Fixnum
    from (irb):14
    from :0
irb(main):015:0> 1.to(9) do |x| print x done
irb(main):016:1> 1.to(9) { |x| print x }
irb(main):017:1> 1.to(9)
irb(main):018:1> 1.upto(9)
irb(main):019:1> 1.upto(9) do |x| print x done
irb(main):020:2> 1.upto(9) { |x| print x }
irb(main):021:2> print "x"
irb(main):022:2> abc
irb(main):023:2> a
irb(main):024:2> b

Upvotes: 4

Views: 2776

Answers (2)

Micha&#235;l Witrant
Micha&#235;l Witrant

Reputation: 7714

IRB is waiting for something to close (in this case the do block on line 15 needs an end).

You can notice this by watching the number after the line number (:0, :1, :2...): while it's positive, IRB wants you to close something.

You can press Ctrl+C to abort the current command and start a new one.

Upvotes: 3

DigitalRoss
DigitalRoss

Reputation: 146053

What happened is that after the error, you typed done instead of end.

Nothing was executed until the block was parsed, but the end never came, so irb just kept reading stuff...

In the future just type ^C or ^D until you get back to the top level or the shell, and then start over.

Upvotes: 5

Related Questions