Irb doesn't print anything

I'm new to ruby. While I'm using irb, something happens (Nothings printed)
Anyone have any advice on this? I donโ€™t even know which search keyword would be ok for this situation.
(maybe an environmental problem?) What 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 
+4
source share
2 answers

It so happened that after the error you typed done instead of end .

Nothing was done until the block figured out, but end never appeared, so irb just kept reading the material ...

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

+5
source

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

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

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

+3
source

Source: https://habr.com/ru/post/1441974/


All Articles