Skip to content

Instantly share code, notes, and snippets.

@bcaplan
bcaplan / keybase.md
Created June 13, 2018 01:05
Keybase Proof

Keybase proof

I hereby claim:

  • I am bcaplan on github.
  • I am bcaplan (https://keybase.io/bcaplan) on keybase.
  • I have a public key ASDTquiwmDT6tF4GIa-JApi5KgCodWLRL2fUyjI6oKRB8go

To claim this, I am signing this object:

#!/usr/bin/env ruby
branch_name = `git rev-parse --abbrev-ref HEAD`
branch_number_regex = /^(\d+)/
matcher = branch_name.match(branch_number_regex)
branch_number = matcher[1] if matcher
if branch_number
path = ARGV[0]
@bcaplan
bcaplan / regexp_parse.rb
Created August 27, 2009 00:57
Adds methods to convert strings to regular expressions
class String
def to_regexp
case self
when /^(\/|%r{)(.*)(\/|})(.*)$/
pattern = $2
parsed = $4.split(/(\S?)/).select { |o| o =~ /(i|x|m)/ }
options = 0
options += Regexp::IGNORECASE if parsed.include? 'i'
options += Regexp::EXTENDED if parsed.include? 'x'
class String
def to_cockney
gsub(/\b[H](.)/) { |letter| letter.upcase }.gsub(/\bh/i, '')
end
end
require 'test_helper'
class CartTest < ActiveSupport::TestCase
def test_initialize
cart = Cart.new
assert_equal 0, cart.items.length
end
def test_add_product
cart = Cart.new