Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. ## scope.rb [ruby]
  2. #!/usr/local/bin/ruby-1.9
  3.  
  4. foo, bar, awk, bla, ook = 1, 2, 3, 4, 5
  5. squee = lambda do |bar,awk;bla|
  6. puts
  7. puts "Inside call, before alter"
  8. puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
  9. puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
  10. puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
  11. puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
  12. puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
  13. puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
  14. foo = -1
  15. bar = -2
  16. bla = -4
  17. ook = -5
  18. don = -6
  19. puts
  20. puts "Inside call, after alter"
  21. puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
  22. puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
  23. puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
  24. puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
  25. puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
  26. puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
  27. end
  28.  
  29. puts "Before call"
  30. puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
  31. puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
  32. puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
  33. puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
  34. puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
  35. puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
  36. squee.call(8,9)
  37. puts
  38. puts "After call"
  39. puts "\tfoo: #{foo.inspect}" rescue puts "\t#{$!}"
  40. puts "\tbar: #{bar.inspect}" rescue puts "\t#{$!}"
  41. puts "\tawk: #{awk.inspect}" rescue puts "\t#{$!}"
  42. puts "\tbla: #{bla.inspect}" rescue puts "\t#{$!}"
  43. puts "\took: #{ook.inspect}" rescue puts "\t#{$!}"
  44. puts "\tdon: #{don.inspect}" rescue puts "\t#{$!}"
  45.  
  46.  
  47. ## Output [plain_text]
  48. adam-gardners-imac-g5:~/code/other projects/ruby adam$ ruby-1.9 scope.rb
  49. Before call
  50. foo: 1
  51. bar: 2
  52. awk: 3
  53. bla: 4
  54. ook: 5
  55. undefined local variable or method `don' for main:Object
  56.  
  57. Inside call, before alter
  58. foo: 1
  59. bar: 8
  60. awk: 9
  61. bla: nil
  62. ook: 5
  63. undefined local variable or method `don' for main:Object
  64.  
  65. Inside call, after alter
  66. foo: -1
  67. bar: -2
  68. awk: 9
  69. bla: -4
  70. ook: -5
  71. don: -6
  72.  
  73. After call
  74. foo: -1
  75. bar: 2
  76. awk: 3
  77. bla: 4
  78. ook: -5
  79. undefined local variable or method `don' for main:Object
Add Comment
Please, Sign In to add comment