%title: Splats: beyond *args %author: weapp %date: 2017-04-20
-> # What is * (splat) <-
source 'https://rubygems.org' | |
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | |
gem 'rails', '~> 6.0.0' | |
# Shorten boot time | |
gem 'bootsnap' | |
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder | |
gem 'jbuilder', github: 'rails/jbuilder' |
ruby '2.7.1' | |
gem 'rails', github: 'rails/rails' | |
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data | |
# Action Text | |
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra' | |
gem 'okra', github: 'basecamp/okra' | |
# Drivers |
#!/usr/bin/env ruby | |
#/ Usage: <progname> [options]... | |
#/ How does this script make my life easier? | |
# ** Tip: use #/ lines to define the --help usage message. | |
$stderr.sync = true | |
require 'optparse' | |
# default options | |
flag = false | |
option = "default value" |
#!/usr/bin/env ruby | |
require "bundler/inline" | |
gemfile do | |
source "https://rubygems.org" | |
gem "rack" | |
gem "foxy", git: "git://github.com/weapp/foxyrb.git" | |
end | |
class App |
class Field | |
attr_accessor :name, :type, :default | |
def initialize(name, type, default) | |
@name = name.to_s | |
@type = type | |
@default = default | |
end | |
TYPECASTS = { |
defmodule PROJECT_NAME.MODULE_NAMETest do | |
use ExUnit.Case | |
alias PROJECT_NAME.MODULE_NAME | |
doctest MODULE_NAME | |
describe "description" do | |
setup do | |
%{ |
source "https://rubygems.org" | |
gem "foxy" | |
group :development, :test do | |
gem "pry" | |
gem "pry-byebug" | |
end |
%title: Splats: beyond *args %author: weapp %date: 2017-04-20
-> # What is * (splat) <-
defmodule MyMap do | |
def bodyrecursive([]) do [] end | |
def bodyrecursive([h|t]) do [h + 1 | bodyrecursive(t)] end | |
def generic_bodyrecursive([], _) do [] end | |
def generic_bodyrecursive([h|t], fun) do [fun.(h) | bodyrecursive(t)] end | |
def tail(list) do tail(list, []) end | |
defp tail([], acc) do :lists.reverse(acc) end | |
defp tail([h|t], acc) do tail(t, [h + 1 | acc]) end |
defmodule Mod do | |
@table %{ | |
a: 1, b: 2, c: 3, d: 4, e: 5, | |
f: 6, g: 7, h: 8, i: 9, j: 0, | |
} | |
def fun1(k) do @table[k] end | |
for {k, v} <- @table do | |
def fun2(unquote(k)) do unquote(v) end |