Module: ConditionalSample
- Defined in:
- lib/conditional_sample.rb,
lib/conditional_sample/public.rb,
lib/conditional_sample/private.rb,
lib/conditional_sample/version.rb
Defined Under Namespace
Modules: MixMe
Class Method Summary collapse
-
.method_assert(object, method_name) ⇒ Object
Raise an error if an object does not respond to a specific method.
-
.to_conditions_array(input, default = nil) ⇒ Object
Convert a hash to array, with key as index.
-
.version_date ⇒ Object
The date of the current version.
-
.version_number ⇒ Object
The number of the current version.
Instance Method Summary collapse
-
#file ⇒ Object
Require everything in the subdirectory.
Class Method Details
.method_assert(object, method_name) ⇒ Object
Raise an error if an object does not respond to a specific method.
21 22 23 24 25 |
# File 'lib/conditional_sample.rb', line 21 def self.method_assert object, method_name unless object.respond_to?(method_name) raise NoMethodError, "Missing method ##{method_name}" end end |
.to_conditions_array(input, default = nil) ⇒ Object
Convert a hash to array, with key as index. Fill any missing elements with a default value.
31 32 33 34 35 36 37 38 |
# File 'lib/conditional_sample.rb', line 31 def self.to_conditions_array input, default = nil return input if input.is_a? Array # Get a list of all Integer keys. # Use the biggest key, and make an array of that length + 1. keys = input.keys.select { |i| i.is_a? Integer } keys.max.next.times.map { |i| input[i] || default } end |
.version_date ⇒ Object
The date of the current version.
21 22 23 |
# File 'lib/conditional_sample/version.rb', line 21 def self.version_date '2017-06-30' end |
.version_number ⇒ Object
The number of the current version.
9 10 11 12 13 14 15 16 |
# File 'lib/conditional_sample/version.rb', line 9 def self.version_number major = 1 minor = 0 tiny = 0 pre = nil string = [major, minor, tiny, pre].compact.join('.') end |
Instance Method Details
#file ⇒ Object
Require everything in the subdirectory.
11 |
# File 'lib/conditional_sample.rb', line 11 Dir[File.dirname(__FILE__) + '/*/*.rb'].each { |file| require file } |