Created
November 2, 2012 16:27
-
-
Save mvidner/4002448 to your computer and use it in GitHub Desktop.
Ruby Variables and Constants
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
#!/usr/bin/env ruby | |
# Ruby Variables and Constants | |
module M | |
variable = 1 | |
CONSTANT = 2 | |
variable = 3 | |
# IMMUTABILITY is not guaranteed | |
remove_const :CONSTANT | |
CONSTANT = 4 | |
begin | |
# UPPERCASE is needed | |
const_set :constant, 5 | |
rescue => e | |
puts e | |
end | |
end | |
puts "M::variable: #{M::variable rescue 'oops'}" | |
# constants are PERSISTENT | |
puts "M::CONSTANT: #{M::CONSTANT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment