Skip to content

Instantly share code, notes, and snippets.

@gom
Created September 18, 2012 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gom/3741153 to your computer and use it in GitHub Desktop.
Save gom/3741153 to your computer and use it in GitHub Desktop.
BEGIN END Control Structures difference in Ruby 1.8.7 and 1.9.3.
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin11.3.0]
$ seq 1 10 | ruby -ne 'BEGIN{ a=0 }; a += $_.to_i; END{ puts a }'
-e:1: undefined method `+' for nil:NilClass (NoMethodError)
$ ruby -v
ruby 1.9.3p135 (2012-02-21 revision 34718) [x86_64-darwin11.2.0]
$ seq 1 10 | ruby -ne 'BEGIN{ a=0 }; a += $_.to_i; END{ puts a }'
55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment