(No shared state between arrays)
input = [[1,2,3,4],[11,12,13,14]]
rows = input
cols = []; rows[0].each_index {|i| cols << rows.map {|r| r[i]}}
pp cols    
#  [[1, 11], [2, 12], [3, 13], [4, 14]]
(No shared state between arrays)
input = [[1,2,3,4],[11,12,13,14]]
rows = input
cols = []; rows[0].each_index {|i| cols << rows.map {|r| r[i]}}
pp cols    
#  [[1, 11], [2, 12], [3, 13], [4, 14]]
| class Table | |
| def initialize(data = [], options = {}) | |
| check_type data | |
| data.each do |row| | |
| check_type row | |
| check_length row, data.first.length | |
| end | |
| @header_support = options[:headers] | 
| class Table | |
| def max_y | |
| @rows[0].length | |
| end | |
| def select_columns | |
| selected = (0..(max_y - 1)).map do |i| | |
| col = @rows.map {|row| row[i] } | 
| # Usage: | |
| # rails new myapp --template=path/to/this/file.rb -J | |
| appname = File.expand_path(Dir.new('.')).split('/').last | |
| #--------------- Gem setup | |
| # Note this is mostly copied from puzzlenode | |
| # | |
| file 'Gemfile', <<_____ | |
| source 'http://rubygems.org' | 
| require 'version_info/data' | |
| require 'version_info/tasks' | |
| module VersionInfo | |
| # current segments or defaults | |
| def self.segments | |
| @segments ||= [:major, :minor, :patch] | |
| end | 
My key requirements were
The commands to add and remove tasks are one-liner bash scripts to echo the command line to ~/.todo, basically. ++ is add, xx is remove. (You can name them whatever you like, of course.)
I think some of the lessons here are useful to the situation of someone who already has learned some programming concepts (grammatical structure), but is struggling with a new programming language, especially one that is based in a different paradigm. Or someone who has a handle on procedural programming for instance (the basic mechanics of doing something with the language), but now is being introduced to compositional/design issues.
In other words: someone who can get by in the language, but is not fluent, and may need help in any number of areas, depending on their background.
| # Note: ripped out of Sinatra, minus any `setting` calls, and disabling inline templates | |
| # Template rendering methods. Each method takes the name of a template | |
| # to render as a Symbol and returns a String with the rendered output, | |
| # as well as an optional hash with additional options. | |
| # | |
| # `template` is either the name or path of the template as symbol | |
| # (Use `:'subdir/myview'` for views in subdirectories), or a string | |
| # that will be rendered. | 
| 1. The ruby singleton, Greg's current thinking | |
| 2. Writing your own enumerator generator for fun and profit | |
| 3. There once was a project named Computer Programming For Everyone |