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
module FunFizzBuzz | |
class ModResult | |
include Comparable | |
attr_accessor :mod, :result_proc | |
def initialize(mod, result_proc) | |
self.mod = mod | |
self.result_proc = result_proc | |
end |
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
def mult_table(num, spaces) | |
max_space = (num * num).to_s.length + spaces | |
rows = [] | |
(1..num).each do |row| | |
rows << (1..num).inject('') { |r,col| r += sprintf("%#{max_space}d", row * col) } | |
end | |
rows | |
end | |
mult_table(12, 2).each { |row| puts row } |