Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.