Skip to content

Instantly share code, notes, and snippets.

@hackjoy
hackjoy / nokogiri_install
Created April 27, 2014 17:46
Installing Nokogiri
NOKOGIRI_USE_SYSTEM_LIBRARIES=1 \
gem install nokogiri -- \
--with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config \
--with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
https://github.com/sparklemotion/nokogiri/issues/1049
@hackjoy
hackjoy / bottles_test_1.rb
Last active August 29, 2015 14:05
bottles test 1
require_relative '../../test_helper'
require_relative '../lib/bottles'
class BottlesTest < Minitest::Test
attr_reader :bottles
def setup
@bottles = ::Bottles.new
end
@hackjoy
hackjoy / bottles_lib_1.rb
Created August 17, 2014 15:37
bottles_lib_1.rb
class Bottles
def verse(num)
"99 bottles of beer on the wall, 99 bottles of beer.\n" +
"Take one down and pass it around, 98 bottles of beer on the wall.\n"
end
end
@hackjoy
hackjoy / bottles_lib_2.rb
Last active August 29, 2015 14:05
bottles_lib_2.rb
class Bottles
def verse(num)
case num
when 89
"89 bottles of beer on the wall, 89 bottles of beer.\n" +
"Take one down and pass it around, 88 bottles of beer on the wall.\n"
when 99
"99 bottles of beer on the wall, 99 bottles of beer.\n" +
"Take one down and pass it around, 98 bottles of beer on the wall.\n"
@hackjoy
hackjoy / bottles_lib_3.rb
Last active August 29, 2015 14:05
bottles_lib_3.rb
class Bottles
def verse(num)
case num
when 0
"No more bottles of beer on the wall, no more bottles of beer.\n" +
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
when 1
"1 bottle of beer on the wall, 1 bottle of beer.\n" +
"Take it down and pass it around, no more bottles of beer on the wall.\n"
@hackjoy
hackjoy / bottles_test_3.rb
Last active August 29, 2015 14:05
bottles_test_3.rb
# ... previous setup and tests not shown for brevity ...
def test_a_couple_verses
expected = <<-VERSES
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.
VERSES
@hackjoy
hackjoy / bottles_lib_4.rb
Last active August 29, 2015 14:05
bottles_lib_4.rb
class Bottles
# ... verse() method not shown for brevity ...
def verses(upper_bound, lower_bound)
"#{verse(upper_bound)}\n#{verse(lower_bound)}"
end
end
@hackjoy
hackjoy / bottles_lib_5.rb
Last active August 29, 2015 14:05
bottles_lib_5.rb
class Bottles
# ... verse() method not shown for brevity ...
def verses(upper_bound, lower_bound)
upper_bound
.downto(lower_bound)
.collect {|verse_number| verse(verse_number)}
.join("\n")
end
@hackjoy
hackjoy / bottles_test_2.rb
Last active August 29, 2015 14:05
bottles_test_2.rb
# ...setup and previous test not shown for brevity ...
def test_another_verse
expected = <<-VERSE
89 bottles of beer on the wall, 89 bottles of beer.
Take one down and pass it around, 88 bottles of beer on the wall.
VERSE
assert_equal expected, bottles.verse(89)
end
@hackjoy
hackjoy / bottles_test_4.rb
Created August 18, 2014 21:08
bottles_test_4.rb
# ... previous setup and tests not shown for brevity ...
def test_a_few_verses
expected = <<-VERSES
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.
Take it down and pass it around, no more bottles of beer on the wall.