This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order | |
has_one :receipt | |
def paid(receipt) | |
self.receipt = receipt | |
end | |
end | |
class Receipt | |
belongs_to :order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Roda | |
module RodaPlugins | |
module Storage | |
def self.configure(app, options: {}) | |
app.opts[:redis] = Redis.new url: (options[:redis_url] || ENV['REDIS_URL']) | |
end | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
class Bass | |
def initialize(hash) | |
@hash = hash | |
end | |
end | |
class Testing < Bass | |
def []=(key, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Streem do | |
def fb(n) when rem(n,15) == 0, do: "FizzBuzz" | |
def fb(n) when rem(n,3) == 0, do: "Fizz" | |
def fb(n) when rem(n,5) == 0, do: "Buzz" | |
def fb(n), do: n | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'rbtrace' | |
proc { | |
Dir.chdir("/tmp") do | |
Dir.pwd | |
Process.pid | |
sleep 30 | |
class Demo < Sinatra::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GithubClient.config do |c| | |
c.endpoint "https://api.github.com/" | |
c.default_handler JSONHandler # handles responses as JSON | |
end | |
class JSONHandler | |
def initialize(data) | |
@data = data | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This... | |
def by_id(id) | |
filter_by(:id, id) | |
end | |
def by_email(email) | |
filter_by(:email, email) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(8)> list = [:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true] | |
[:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true] | |
iex(9)> is_list list | |
true | |
iex(10)> :erlang.list_to_binary list | |
** (ArgumentError) argument error | |
:erlang.list_to_binary([:width, 1024, :height, 768, :content_type, "image/png", :postProcess, true]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "Run migrations" | |
task :migrate, [:version] do |t, args| | |
require "sequel" | |
Sequel.extension :migration | |
db = Sequel.connect(ENV.fetch("DATABASE_URL")) | |
if args[:version] | |
puts "Migrating to version #{args[:version]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$> rspec test_case.rb | |
F. | |
Failures: | |
1) a failing case expects success | |
Failure/Error: expect(production_code(response)).to eq 'success' | |
expected: "success" | |
got: "failure" |