Sorbet can help with type inference in tests if the setup is right. Otherwise types will be reduced to T.untyped
.
class Test < ActiveSupport::TestCase
def setup # Don't use `dev setup`.
@user = make_fixture(User, :alex) # Don't forget `T.let`
Sorbet can help with type inference in tests if the setup is right. Otherwise types will be reduced to T.untyped
.
class Test < ActiveSupport::TestCase
def setup # Don't use `dev setup`.
@user = make_fixture(User, :alex) # Don't forget `T.let`
(This is just one recommendation - and doesn't talk about error-free data structure design.)
Let's say there is a Project
class that needs a convenience builder for testing.
This Project
consist of a company who owns the project and a list of tickets - where a ticket is just a name and the same company denormalized (for reasons).
Since this company attribute is just a denormalization - it is/must-be consistent.
/* | |
* The task is to write a ~Java~ Rust program which reads the file, calculates the | |
* min, mean, and max temperature value per weather station, and emits the results | |
* on stdout like this (i.e. sorted alphabetically by station name, and the result | |
* values per station in the format <min>/<mean>/<max>, rounded to one fractional digit): | |
* | |
* { | |
* Abha=-23.0/18.0/59.2, | |
* Abidjan=-16.2/26.0/67.3, | |
* Abéché=-10.0/29.4/69.0, |
# Terminal Tetris | |
# | |
# Usage: | |
# | |
# ```bash | |
# ruby tetris.rb <WIDTH> <HEIGHT> <SPEED> | |
# ``` | |
# | |
# Control: | |
# - a: left |
note = File.read(ARGV[0]) | |
gid = 1 | |
prev_indent = 0 | |
stack = [0] | |
labels = ["Root"] | |
edges = [] | |
note.lines.map { _1.delete!("\n") }.map do |line| |
This is a short debugging story that led to a few learnings. Our team is working on making TruffleRuby support one of our larger internal Ruby application. Running tests in CI we've noticed a flaky test failure reporting:
undefined method 'write_without_cli_ui' for #<IO:<STDOUT>> (NoMethodError)
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#define PIPE_MAX (1 << 16) | |
int main() { | |
int pipefd[2]; |
=begin | |
Extracts a block of subtree from a callgraph of a given function (matched by a substring). | |
Use: | |
jt ruby --cpusampler=calltree -e 'a=[];a.push(1);p(a.size)' | ruby truffle_calltree_find.rb "IO#puts" | |
=end |
=begin | |
WADIS is a Redis variable watcher. | |
Usage: | |
```shell | |
ruby wadis.rb <HOST> <PORT> --hkey=<key1>,<key2>... --vkey=<key1>,<key2>... | |
``` |
require("thread") | |
class Foo | |
def initialize(arr) | |
@arr = arr | |
end | |
def update | |
i = @arr[-1] | |
@arr.push(i + 1) |