Skip to content

Instantly share code, notes, and snippets.

@nagachika
nagachika / husband.rb
Created April 19, 2013 16:06
a joke example of refinements.
class Husband
attr_accessor :affair
def say
puts "I love my wife."
end
end
module Secret
refine Husband do
def say
@nagachika
nagachika / gist:4324067
Created December 18, 2012 01:11
make test-all TESTS=ruby/test_require.rb
# Running tests:
[21/27] TestRequire#test_require_to_path_redefined_in_load_path = 0.07 s
1) Failure:
test_require_to_path_redefined_in_load_path(TestRequire) [/Users/nagachika/opt/ruby-trunk/src/ruby/test/ruby/test_require.rb:504]:
[ruby-core:47970].
<[":ok"]> expected but was
<["[:ng, [\"/Users/nagachika/opt/ruby-trunk/src/build\", \"/Users/nagachika/opt/ruby-trunk/src/build/.ext/common\", \"/Users/nagachika/opt/ruby-trunk/src/build/.ext/x86_64-darwin12.2.0\", \"/Users/nagachika/opt/ruby-trunk/src/ruby/lib\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/site_ruby/2.0.0\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/site_ruby/2.0.0/x86_64-darwin12.2.0\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/site_ruby\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/vendor_ruby/2.0.0\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/vendor_ruby/2.0.0/x86_64-darwin12.2.0\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/vendor_ruby\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/2.0.0\", \"/Users/nagachika/opt/ruby-trunk/lib/ruby/2.0
load 'deploy' if respond_to?(:namespace)
load 'config/deploy'
require "capistrano_colors"
set :stages, %w(sample_stage)
set :default_stage, "sample_stage"
require 'capistrano/ext/multistage'
@nagachika
nagachika / Rakefile
Created May 15, 2012 16:37 — forked from jugyo/Rakefile
the db:migrate task using ActiveRecord without Rails
require 'bundler/setup'
require 'active_record'
require 'logger'
namespace :db do
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end
@nagachika
nagachika / gist:2703119
Created May 15, 2012 16:36 — forked from jugyo/gist:2624955
How to use ActiveSupport::Dependencies.autoload_paths
require 'active_support/dependencies'
ActiveSupport::Dependencies.autoload_paths << File.expand_path('../lib', __FILE__)
@nagachika
nagachika / example_lazy_flat_map.rb
Created March 9, 2012 06:59
example of Enumerable::Lazy#flat_map
ary = (0..10).to_a
o = Object.new
o.instance_variable_set(:@ary, ary)
def o.to_ary
@ary
end
l = [o].lazy.flat_map{|x| x}
p l.next # => 0
ary.clear
@nagachika
nagachika / puzzle_1.alloy
Created February 5, 2012 06:24
alloy exercise for a puzzle
enum Cap { Black, White }
abstract sig Children {
cap: one Cap,
visible: set Children
}
one sig A extends Children {} {
visible = none
cap = Black
@nagachika
nagachika / godscope.rb
Created January 26, 2012 04:33
godscope
# `publish' all private instance methods
ObjectSpace.each_object(Module) do |mod|
mod.private_instance_methods(false).each do |meth|
mod.__send__(:public, meth)
end
end
# define accessor methods as ghost method
class Object
def method_missing(meth, *args)
@nagachika
nagachika / test_io.rb.patch
Created January 6, 2012 17:29
patch for test_autoclose
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 76eb82c..0fbec35 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1409,13 +1409,15 @@ class TestIO < Test::Unit::TestCase
end
def try_fdopen(fd, autoclose = true, level = 100)
- if level > 0
- try_fdopen(fd, autoclose, level - 1)
diff --git a/lib/test/unit.rb b/lib/test/unit.rb
index eb0666a..00313a3 100644
--- a/lib/test/unit.rb
+++ b/lib/test/unit.rb
@@ -457,7 +457,9 @@ module Test
bang = $1
worker.status = :ready
if @tasks.empty?
- break unless @workers.find{|x| x.status == :running }
+ unless @workers.find{|x| [:running, :prepare].include? x.status}