Skip to content

Instantly share code, notes, and snippets.

View justincampbell's full-sized avatar
🌯
🍩

Justin Campbell justincampbell

🌯
🍩
View GitHub Profile
## x27[32mmasterx27[m...x27[31morigin/masterx27[m [ahead x27[32m1x27[m]
## x27[32mmasterx27[m...x27[31morigin/masterx27[m
import rg
from random import choice
class Robot:
def act(self, game):
ranges = [-1, 0, 1]
x = self.location[0] + choice(ranges)
y = self.location[1] + choice(ranges)
moves = [
['move', (x, y)],

Features

  • Run for length of time
  • Run for number of iterations
  • Run for both and stop at whichever comes first
  • Reuse RSpec structure
  • Running semantics:
    • I want to run for N iterations limited to X minutes in CI
    • I want to run for a few seconds with rake
  • I want to run for a shorter period of time with guard

DSL

require 'something'
require 'something/rspec'

describe String do
  describe "#wrap" do
    it "wraps" do
 expect("test foo".wrap(4)).to eq("test\nfoo")
require 'spec_helper'
require 'mrproper'
properties 'String' do
data string: String, wrap_at: Integer
property '#wrap' do |data|
assert_not_empty data[:string].wrap(data[:wrap_at])
end
class Temperature
DEGREE_SIGN = "°"
attr_reader :value, :scale
def initialize(value, scale)
@value = value.to_f.round(1)
@scale = TemperatureScale.from_symbol(scale)
end
class Temperature
DEGREE_SIGN = "°"
attr_reader :value, :scale
def initialize(value, scale)
@value = value.to_f.round(1)
@scale = TemperatureScale.from_symbol(scale)
end
class Temperature
attr_reader :value, :scale
def initialize(value, scale = :farenheit)
@value = Float(value)
@scale = scale
end
def to_celcius
return self if scale == :celcius
def new(klass, *args)
klass.new(*args)
end
(p (new String)) # => ""
def concat(*strings)
strings.join
end
class Module
def callable
klass_name = if defined?(:caller_locations)
caller_locations(1, 1)[0].label[8..-2]
else
caller[0][/`.*'/][9..-3]
end
klass = Kernel.const_get(klass_name)