View object_model.txt
1 2 3 4 5 6 7 8 9 10
Scopes (triangles)
local variables
pointer to previous scope
pointer to self
 
Objects (Circles)
instance variables
pointer to class
 
Classes (Squares)
View generate_boolean_challenges.rb
1 2 3 4 5 6 7 8 9 10
puts (2**9).times
.map { |iteration|
'%{paren1left}%{negation1}%{bool1} %{op1} %{paren2left}%{negation2}%{bool2}%{paren1right} %{op2} %{negation3}%{bool3}%{paren2right}' % {
bool1: iteration[0].zero?,
bool2: iteration[1].zero?,
bool3: iteration[2].zero?,
negation1: iteration[3].zero? ? '' : '!',
negation2: iteration[4].zero? ? '' : '!',
negation3: iteration[5].zero? ? '' : '!',
View quiz.md

Quiz time!

  • What does the dot mean in in StringIO.new, what does the hash mean in StringIO#puts?
  • How do you make a String literal?
  • How do you make a String without using a literal?

This is an HTTP request, it is a String that is sent across a Socket, which your program can read from as if it were a file or $stdin.

01 POST /users/5?omg=wtf&bbq=lol HTTP/1.1\r\n
View garden1.rb
1 2 3 4 5 6 7 8 9 10
class Garden
ABBREVIATIONS = {
'R' => :radishes,
'C' => :clover,
'G' => :grass,
'V' => :violets,
}
 
ABBREVIATIONS.default_proc = lambda do |abbreviations, abbreviation|
raise KeyError,
View hoisting.rb
1 2 3 4 5 6 7 8 9 10
# generic hoisting
if true
a = 1
end
a # => 1
 
 
begin
b = 2
end
View yield_while.rb
1 2 3 4 5 6 7 8 9 10
def yield_while(&block)
Enumerator.new do |y|
while value = block.call
y.yield value
end
end
end
 
require 'stringio'
stream = StringIO.new "abc\ndef\nghi\n"
View writing_to_the_data_segment.rb
1 2 3 4 5 6
File.open(DATA, 'r+') do |file|
file.seek DATA.pos
file.puts "#{DATA.read.to_i.next} <-- this number will increment each time you run the file"
end
__END__
0 <-- this number will increment each time you run the file
View state_machine.rb
1 2 3 4 5 6 7 8 9 10
# om = OrderMachine.new(@order.order_status)
#
# om.transitionable_states.each do |state|
# form_for(order, url: admin_order_path(@order)) do |f|
# f.hidden_field :status, value: state
# f.submit state.capitalize
# end
# end
 
class OrderMachine
View example_integration_test.rb
1 2 3 4 5 6 7 8 9 10
class Transaction
attr_reader :name, :invoice_id
def initialize(name:, invoice_id:, repo:)
@name = name
@invoice_id = invoice_id
@repo = repo
end
def invoice
@repo.invoice(@invoice_id)
Something went wrong with that request. Please try again.