Last active
February 18, 2016 09:19
-
-
Save envp/12e08aeb038ebd9e2ee2 to your computer and use it in GitHub Desktop.
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
| # require all the rngs defined in lib/statistical/rng | |
| require 'statistical/rng/uniform' | |
| module Statistical | |
| module Rng | |
| # :nodoc: | |
| # Dynamically add constant RNG_TYPES when called | |
| def self.const_missing(cname) | |
| if cname == 'RNG_TYPES'.to_sym | |
| self.const_set(cname, make_classmap) | |
| end | |
| end | |
| def self.create(type = :uniform, *args) | |
| RNG_TYPES[type].new(*args) | |
| end | |
| private | |
| def self.make_classmap | |
| rng_klasses = self.constants.select{ |k| self.const_get(k).is_a?(Class) } | |
| keylist = rng_klasses.map { |k| k.to_s.downcase.to_sym } | |
| klasses = rng_klasses.map { |k| self.const_get(k) } | |
| return Hash[keylist.zip(klasses)].freeze | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment