Module: StairCar::InitMethods
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/stair_car/shared/init_methods.rb', line 47 def self.included(klass) klass.extend(ClassMethods) klass.init_method_names do |method_name, sparse, type, initialize_values| klass.define_singleton_method(method_name) do |cols, rows| klass.new(cols, rows, type, sparse, initialize_values) end end end |
Instance Method Details
#array_dimensions(array) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stair_car/shared/init_methods.rb', line 15 def array_dimensions(array) if array.first.is_a?(Array) # Nested array rows = array.size cols = array.first.size else # 1 dimensional array cols = array.size rows = 1 end return rows, cols end |
#from_array(array, klass) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/stair_car/shared/init_methods.rb', line 3 def from_array(array, klass) rows, cols = array_dimensions(array) if klass.is_a?(Method) || klass.is_a?(Proc) @data = klass.call(rows, cols) else @data = klass.new(rows, cols) end self[nil,nil] = array end |