View setup.rb
class Package < Struct.new(:command, :name, :opts)
def install!
if not_installed?
system("#{command} install #{name} #{opts.join(" ")}")
end
end
def not_installed?
!exists?
end
View example.css
html {
background: #F7F7F7;
color: red;
height: 100%;
}
body {
min-height: 100%;
}
.wrapper {
View Main.elm
module Main exposing (..)
import Html exposing (Html, div, text)
import Dict exposing (Dict)
names : String -> Dict String (List String)
names str =
str
|> String.split ", "
|> List.map (\name -> String.split " " name)
View either_or.rb
# Structured and Nested
obj = {
container_a = {
name: "Foo",
contents: [item_a, item_b, item_e]
}
container_b = {
name: "Bar",
contents: [item_c, item_d, item_z]
}
View test.rb
it 'sets the state to "gameover" when there is a winner' do
game = Game.new
game.state = "running"
expect { game.winner! }.to change { game.state }.from("running").to("gameover")
end
View Main.elm
module Main exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.App as App
import Html.Events exposing (onInput, onBlur, onClick)
import String exposing (length, left, dropLeft, slice, filter, fromList, toList)
import Char exposing (isDigit)
import Json.Decode as JsonD
import Json.Encode as JsonE
View kata.rb
#!/usr/bin/env ruby
# This script will create the folder structure and files
# needed for doing a kata using TDD.
kata_name = (ARGV[0] || 'morning')
dir_name = kata_name + "_kata"
# These are all the commands we will run
# in the order in which we will run them.
View commands.sh
rm my_blog.db ; ruby seed.rb | sqlite3 my_blog.db && sqlite3 my_blog.db
View introspection_fun.rb
def inspect_class(klass)
klass.new.methods.sort.each do |meth|
just = klass.new.methods.sort.max_by(&:length).length
hjust = just / 2
klass_meth = klass.new.method(meth)
label = "#{klass}.new.#{meth.to_s.ljust(just)}"
location = "is defined in #{klass_meth.owner.to_s.ljust(hjust)}"
response = [label, location]