View allocation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Allocation = Struct.new(:project, :person, :start, :finish) do | |
include Comparable | |
def mergable_with?(other) | |
if start > other.start | |
other.mergable_with?(self) | |
else | |
same_assignment?(other) && | |
finish >= other.start - 1 | |
end |
View beer_song_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'minitest' | |
require 'minitest/autorun' | |
require './beer_song' | |
class BeerSongTest < Minitest::Test | |
V8 = | |
"8 bottles of beer on the wall, 8 bottles of beer.\n" + | |
"Take one down and pass it around, 7 bottles of beer on the wall.\n" |
View sample.new.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new | |
allocate.tap { |obj| obj.initialize } | |
end |
View Rakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rake/clean' | |
require 'rake/testtask' | |
task :default => [:spec, :test] | |
task :spec do | |
sh "rspec ." | |
end |
View weird.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(a=:default, b) | |
puts "a=#{a}, b=#{b}" | |
end | |
foo(:value) | |
foo(:x, :y) |
View configure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def project(name, &block) | |
Project.new(name, &block) | |
end | |
class Project | |
def initialize(name, &block) | |
@name = name | |
@context = eval("self", block.binding) | |
instance_eval(&block) if block_given? |
View run.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rspec xx_spec.rb | |
.... | |
Finished in 0.00287 seconds | |
4 examples, 0 failures |
View spy_test_fragment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_spy | |
d = flexmock(f: :ok) | |
assert_equal :ok, d.f("Woof",2) | |
assert_spy_called d, :f, String, Integer | |
end |
View JRuby_Output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SOURCE: defined?(a) | |
RESULT: | |
[:program, [:stmts_add, [:stmts_new], [:defined, [:@rparen, ")", [1, 10]]]]] | |
SOURCE: "my name is #{name}" | |
RESULT: | |
[:program, | |
[:stmts_add, | |
[:stmts_new], | |
[:string_literal, |
View sqrt_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
Sqrt = ->(n) { | |
guess = n / 2.0 | |
loop do | |
if (guess**2 - n) < 0.0001 | |
return guess | |
end | |
guess = (guess + n/guess) / 2.0 | |
end |
NewerOlder