Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created November 2, 2012 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/4002448 to your computer and use it in GitHub Desktop.
Save mvidner/4002448 to your computer and use it in GitHub Desktop.
Ruby Variables and Constants
#!/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