Skip to content
View 0_explanation.md

Matrix Multiplication...

An ill fitting metaphor?

Matrix multiplication is not commutative.

This is very unintuitive, especially once they replace it with variables. At which point you get equations that look the same, but behave very differently.

View modules.md

Modules

To understand modules, we first have to understand a little bit about how Ruby works. So, lets define the things that exist in Ruby and see how they work together. Then, we will be able to understand how modules fit into this, and what they are here for.

Definitions

View visualize_gol.rb
# ===== Game of Life visualizer =====
# You need to fill out these three methods
# and it will visualize your game
# input: an array of xy pairs, an xy pair is an array of 2 integers for a living cell
# output: whatever object you made to implement the game of life
def init(xy_pairs)
cells = Array.new(200) do |y|
Array.new(200) { |x| xy_pairs.include? [x, y] }
View seeing_a_compiled_method.rb
# Classes store a hash of methods, the keys being the method names... but what are the values?
# Here you can see an example of what the code looks like when compiled.
# It's not important to understand how these instructions allow Ruby to work,
# but I want you to see that there is a concrete thing there that you can look at.
# (note, all of the `trace` instructions are irrelevant and can be ignored,
# their purpose is to allow you to hook into events from the outside http://www.rubydoc.info/stdlib/core/TracePoint)
def greet
puts "hello world"
end
View example_high_level_app.rb
require 'active_record'
require 'erb'
require 'logger'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.logger = Logger.new $stdout
ActiveSupport::LogSubscriber.colorize_logging = false
ActiveRecord::Schema.define do
self.verbose = false
View estimate_pi.rb
# solution for http://www.reddit.com/r/dailyprogrammer/comments/3f0hzk/20150729_challenge_225_intermediate_estimating_pi/
require 'set'
require 'chunky_png'
# load the image from the data segment
raw_png = DATA.read.delete("\n").unpack('m0').first
image = ChunkyPNG::Image.from_blob(raw_png)
# extract the colours
colours = image.pixels.uniq
View rails_engine.rb
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
self.verbose = false
create_table "invoice_items" do |t|
t.integer "invoice_id"
t.integer "quantity"
View object_model.md

Module 4 Object Model with 1502!

Recap

Some definitions

  • Containers Hashes whose keys are Symbols
  • Pointers Fixnum whose value is a location in memory
View sorted_merging.rb
# https://github.com/turingschool/challenges/blob/d7f7d3e726ce95667ed3f1e1996de2895efadc7c/sorted_merging.markdown
# I accidentally closed the window I wrote the solution in,
# so I couldn't find it, but I rewrote it. I shortened the names,
# so that I could get some of the ideas downt o one line.
# Also, thought of a way cooler way to implement our `smallest` method :)
def smallest(one, two)
[one, two].min_by(&:first)
end
View balanced_bst.rb
class BalancedBst
module Empty
extend self
def <<(data)
BalancedBst.new data
end
def >>(data)
self
end
Something went wrong with that request. Please try again.