Skip to content

Commit 79f1cd0

Browse files
committed
File on variable scope.
Only covers local scope.
1 parent 5d78eea commit 79f1cd0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

custom-methods/variable-scope.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!usr/bin/env ruby
2+
3+
# A local variable called value defined on the file itself.
4+
value = 10
5+
6+
# A method with its own local variable called value.
7+
def output_value
8+
value = 5
9+
puts value
10+
end
11+
12+
# Both variables were defined in their local scopes, therefore they print different values.
13+
output_value # Will print 5, not 10.
14+
puts value # Will print 10, not 5.

0 commit comments

Comments
 (0)