Module: Factree::FactSource::ClassMethods
- Defined in:
- lib/factree/fact_source.rb
Instance Method Summary collapse
-
#def_fact(fact_name, &block) ⇒ Object
Defines a named fact along with a block used to compute the fact’s value.
-
#defined?(fact_name) ⇒ Boolean
True if the fact has been defined (using FactSource.def_fact).
-
#fact_names ⇒ Array<Symbol>
Names for all of the defined facts, whether their values are known or not.
- #fact_procs ⇒ Object private
Instance Method Details
#def_fact(fact_name, &block) ⇒ Object
Defines a named fact along with a block used to compute the fact’s value.
15 16 17 18 19 20 21 |
# File 'lib/factree/fact_source.rb', line 15 def def_fact(fact_name, &block) raise ArgumentError, "block required" unless block_given? all_fact_procs = fact_procs.merge(fact_name => block).freeze class_variable_set(:@@_fact_procs, all_fact_procs) fact_name end |
#defined?(fact_name) ⇒ Boolean
Returns True if the fact has been defined (using FactSource.def_fact).
36 37 38 |
# File 'lib/factree/fact_source.rb', line 36 def defined?(fact_name) fact_procs.include? fact_name end |
#fact_names ⇒ Array<Symbol>
Returns Names for all of the defined facts, whether their values are known or not.
24 25 26 |
# File 'lib/factree/fact_source.rb', line 24 def fact_names fact_procs.keys.freeze end |
#fact_procs ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 32 33 |
# File 'lib/factree/fact_source.rb', line 29 def fact_procs class_variable_defined?(:@@_fact_procs) ? class_variable_get(:@@_fact_procs) : {}.freeze end |