Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## scope.rb [ruby]
- #!/usr/local/bin/ruby-1.9
- foo, bar, awk, bla, ook = 1, 2, 3, 4, 5
- squee = lambda do |bar,awk;bla|
- puts
- puts "Inside call, before alter"
- puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
- puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
- puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
- puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
- puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
- puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
- foo = -1
- bar = -2
- bla = -4
- ook = -5
- don = -6
- puts
- puts "Inside call, after alter"
- puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
- puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
- puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
- puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
- puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
- puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
- end
- puts "Before call"
- puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
- puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
- puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
- puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
- puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
- puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
- squee.call(8,9)
- puts
- puts "After call"
- puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
- puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
- puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
- puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
- puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
- puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
- ## Output [plain_text]
- adam-gardners-imac-g5:~/code/other projects/ruby adam$ ruby-1.9 scope.rb
- Before call
- foo: 1
- bar: 2
- awk: 3
- bla: 4
- ook: 5
- undefined local variable or method `don' for main:Object
- Inside call, before alter
- foo: 1
- bar: 8
- awk: 9
- bla: nil
- ook: 5
- undefined local variable or method `don' for main:Object
- Inside call, after alter
- foo: -1
- bar: -2
- awk: 9
- bla: -4
- ook: -5
- don: -6
- After call
- foo: -1
- bar: 2
- awk: 3
- bla: 4
- ook: -5
- undefined local variable or method `don' for main:Object
Add Comment
Please, Sign In to add comment