Avdi Grimm's book has a section on guard classuses showing a refactor from
# From
def log_reading(reading_or_readings)
readings = Array(reading_or_readings)
readings.each do |reading|
puts "[Reading] %3.2f" % reading.to_f
end
end
puts ->() { # print out the result | |
script = ->(b) { # accessory funciton to beer improver to improve readability. | |
puts "#{b} bottles of beer on the wall. #{b} bottles of beer." | |
puts "you take one down, pass it around, #{b-1} bottles of beer on the wall." | |
} | |
beer_improver = ->(partial) { # a function that does any one bottle of beer on the wall. | |
->(n) { n.zero? ? "no more bottles" : ->(b) {script.(b); return partial.(b)}.(n-1)}} | |
y = ->(improver) { # Church's Y-Combinator. | |
->(gen) { gen.(gen) }.(->(gen) {beer_improver.(->(v) {gen.(gen).(v)})})} |
puts "double assignment:" | |
puts Benchmark.measure { | |
100_000_000.times { "abc" } | |
} | |
# double assignment: | |
# 9.320000 0.010000 9.330000 ( 9.316967) | |
puts "double comparisons:" | |
x = "a" |
x = []
10_000_000.times {
x = x.concat([1])
}
p GC.stat
x = []
10_000_000.times {
I hereby claim:
To claim this, I am signing this object:
module SqlParser exposing (..) | |
import Parser exposing ((|.), (|=), Parser, Trailing(..), float, keyword, spaces, succeed, symbol) | |
import Set | |
type alias Query = | |
{ select : List SelectField | |
, from : String | |
} |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class looker : MonoBehaviour | |
{ | |
[SerializeField] private GameObject target; | |
[SerializeField] private float viewAngle = 30f; | |
[SerializeField] public RaycastHit hit; |
#include <raylib.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
struct Target { | |
Vector2 position; | |
int size | |
}; | |
⋊> ~/c/ruby on getlocal-of-same-object-becomes-dup ⨯ ./ruby --version 15:27:30 | |
ruby 3.1.0dev (2021-03-17T21:17:37Z getlocal-of-same-o.. 383292776f) [x86_64-darwin19] | |
⋊> ~/c/ruby on getlocal-of-same-object-becomes-dup ⨯ /Users/hparker/.rbenv/shims/ruby --version 15:27:53 | |
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] | |
⋊> ~/c/ruby on getlocal-of-same-object-becomes-dup ⨯ benchmark-driver benchmark/repeated_local.rb -e ./ruby -e /Users/hparker/.rbenv/shims/ruby 15:27:55 | |
Calculating ------------------------------------- | |
./ruby /Users/hparker/.rbenv/shi |
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails", branch: "main" |