Created
April 17, 2014 04:02
-
-
Save havenwood/10952043 to your computer and use it in GitHub Desktop.
Object#constants_hash.
This file contains 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
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