Created
October 13, 2014 05:37
-
-
Save ifyouseewendy/524d8285d4f9a910dce5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Note from Ruby Pocket Reference | |
# | |
# Since constants refer to objects, the contents of the object | |
# to which the constant refers may change without Ruby generating | |
# a warning. Thus, Ruby constants are called *mutable*, because, | |
# although the constant is only expected to refer to a single | |
# object throughout the program, what's contained in that object | |
# may vary. | |
FOO = 'a' | |
FOO = 'b' | |
puts "FOO is #{FOO}" | |
class Bar | |
attr_accessor :name | |
end | |
bar = Bar.new | |
bar.name = 'a' | |
BAR = bar | |
puts "BAR's name is #{BAR.name}" | |
bar.name = 'b' | |
puts "BAR's name is #{BAR.name}" | |
##### OUTPUT | |
# constant_reference.rb:2: warning: already initialized constant FOO | |
# constant_reference.rb:1: warning: previous definition of FOO was here | |
# FOO is b | |
# BAR's name is a | |
# BAR's name is b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment