Skip to content

Instantly share code, notes, and snippets.

View cwgem's full-sized avatar

Chris White cwgem

View GitHub Profile
@cwgem
cwgem / symbol.rb
Created July 27, 2011 03:50
Rubyシンボルとユニットテストの注意するところ
require "test/unit"
class TestLibraryFileName < Test::Unit::TestCase
def my_method
end
def test_symbol
assert_equal true, Symbol.all_symbols.include?(:my_method)
end
@cwgem
cwgem / about_symbols.rb
Created July 27, 2011 03:52
about_symbols.rbのtest_method_names_become_symbols
def test_method_names_become_symbols
symbols_as_strings = Symbol.all_symbols.map { |x| x.to_s }
assert_equal true, symbols_as_strings.include?("test_method_names_become_symbols")
end
$ ruby symbol_test.rb
Loaded suite symbol_test
Started
..
Finished in 0.001946 seconds.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 40647
@cwgem
cwgem / block_test.rb
Created July 27, 2011 15:39
ブロック引数の取り込み
def my_block_method
if block_given?
(["hello"] * 3).each { | x |
yield x
}
end
end
my_block_method { | x |
puts x
@cwgem
cwgem / block_test.rb
Created July 27, 2011 15:39
ブロック引数の取り込み
def my_block_method
if block_given?
(["hello"] * 3).each { | x |
yield x
}
end
end
my_block_method { | x |
puts x
@cwgem
cwgem / gist:1109961
Created July 27, 2011 17:47
thin + rails newアップ
SOLAR:~ chriswhite$ ab -n 2000 -c 100 http://localhost:3000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
@cwgem
cwgem / tap.rb
Created July 27, 2011 21:23
tap使用例
# encoding: UTF-8
Dir.glob("*").tap {|files|
puts "ファイル数: #{files.length}"
}.each {|filename|
puts "ファイル情報: 【名前】 #{filename} 【サイズ】 #{File.stat(filename).size}"
}
# ファイル数: 6
# ファイル情報: 【名前】 binding.rb 【サイズ】 46
@cwgem
cwgem / tap.rb
Created July 27, 2011 21:38
tap使用例その2
# encoding: UTF-8
Dir.glob("*").tap {|files|
files = []
}.each {|filename|
puts "ファイル情報: 【名前】 #{filename} 【サイズ】 #{File.stat(filename).size}"
}
# ファイル情報: 【名前】 binding.rb 【サイズ】 46
# ファイル情報: 【名前】 block_test.rb 【サイズ】 137
@cwgem
cwgem / object_mangling.rb
Created July 27, 2011 22:04
席の問題
require "test/unit"
class ObjectMangling
attr_accessor :seki
def remove
remove_instance_variable(:@seki)
end
end
class TestLibraryFileName < Test::Unit::TestCase
@cwgem
cwgem / data.rb
Created July 28, 2011 03:22
DATAの使用例
require "yaml"
puts YAML::load( DATA.read ).inspect
__END__
---
- dogs
- cats
- badgers