Don't name a method "next"!
-
Here is
bug_splat.rb
, which does as its name suggests when you try to load it.def bug_splat() next() end
Edit: typing
next()
into the Ruby Console gets a Bug Splat. -
Hey cool, it "works" the same if you just type it in the Ruby Console.
next
does not bugsplat,next()
does. -
next
is a Ruby reserved keyword used to control loop iteration. -
next
is also a method meaning "give me the next value."1.next ==> 2 "a".next ==> "b"
-
-
Try it from the rerula - non SU ruby command line editor. I doubt it will give a bugsplat Maybe it just returns an error, or critical error or something.
-
@jim said:
next
is also a method meaning "give me the next value."1.next ==> 2 "a".next ==> "b"
Good point. But that leads to the question; is "reserved" really reserved in Ruby?
Sonext
can be class method, but not a root method? -
let's see (Mac, ruby 1.8.6, command line)
irb >> next() LocalJumpError; unexpected next from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/workspace.rb;81;in `evaluate' Maybe IRB bug!! ruby -e "next()" -e;1; unexpected next (LocalJumpError)
so it is more a ruby problem than a SU. but why the exception is not trapped by SU ?
-
Windows7, Ruby 1.8.0 - Console Session (IRB)
C;\Users\Thomas>irb irb(main);001;0> next() LocalJumpError; unexpected next from C;/Ruby/lib/ruby/1.8/irb/workspace.rb;81;in `evaluate' from C;/Ruby/lib/ruby/1.8/irb/context.rb;219;in `evaluate' from C;/Ruby/lib/ruby/1.8/irb.rb;150;in `eval_input' from C;/Ruby/lib/ruby/1.8/irb.rb;263;in `signal_status' from C;/Ruby/lib/ruby/1.8/irb.rb;147;in `eval_input' from C;/Ruby/lib/ruby/1.8/irb/ruby-lex.rb;244;in `each_top_level_statement' from C;/Ruby/lib/ruby/1.8/irb/ruby-lex.rb;230;in `loop' from C;/Ruby/lib/ruby/1.8/irb/ruby-lex.rb;230;in `each_top_level_statement' from C;/Ruby/lib/ruby/1.8/irb/ruby-lex.rb;229;in `catch' from C;/Ruby/lib/ruby/1.8/irb/ruby-lex.rb;229;in `each_top_level_statement' from C;/Ruby/lib/ruby/1.8/irb.rb;146;in `eval_input' from C;/Ruby/lib/ruby/1.8/irb.rb;70;in `start' from C;/Ruby/lib/ruby/1.8/irb.rb;69;in `catch' from C;/Ruby/lib/ruby/1.8/irb.rb;69;in `start' from C;/Ruby/bin/irb;13 Maybe IRB bug!! irb(main);002;0> exit C;\Users\Thomas>
Advertisement