Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created April 17, 2014 04:02
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 havenwood/10952043 to your computer and use it in GitHub Desktop.
Save havenwood/10952043 to your computer and use it in GitHub Desktop.
Object#constants_hash.
class Object
def constants_hash
constants = self.constants
constant_values = constants.map do |const|
self.const_get const
end
constants.zip(constant_values).to_h
end
end
require 'mathn'
Math.constants_hash
#=> {:DomainError=>Math::DomainError,
:PI=>3.141592653589793,
:E=>2.718281828459045}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment