• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

たいしたものではないですが、
iPhoneアプリ開発用に
Linked ListとLRUCacheを実装したユーティリティライブラリを公開します。

http://github.com/genki/s21gutils/tree/master

本当はサードパーティフレームワークの形にしたかったんですが、
iPhoneでサポートされてないようなので、ソースとUnitTest用プロジェクトの形で公開します。

ヘッダファイルをコピーとかするのが面倒なので、
Gitでソースを管理してるプロジェクトで使う場合は、
以下のようにGit submoduleとして追加するとメンテナンスが楽かもです。

pre>>
% git submodule add http://github.com/genki/s21gutils/tree/master Classes/s21gutils
<<--

Public Domainです。無償・商用問わず自由に使ってください。
よろしくお願いします。

posted by genki genki on Sun 2 Nov 2008 at 07:55 with 0 comments

I made a small utility library named
Wormhole.
The library enables us to communicate between caller and callee.

Here is a simple example of use.

ruby>>
require 'rubygems'
require 'wormhole'

def foo(array)
array << :foo # (1)
Wormhole.throw array
array << :baz # (3)
end

result = Wormhole.catch do
foo []
end.return do |array|
array << :bar # (2)
end
puts result.inspect # => [:foo, :bar, :baz]
<<--

First, the block passed to Wormhole.catch, the caller, is evaluated.
The foo method, the callee, throw an array object passing through the wormhole.
Then the array is caught by the last block passed to a return method. A block parameter of the block is the array.
Finally, the process goes back to the point 3 after the last block ends.
A return value of the foo method is returned via the return method.

By using this utility, you can participate to a depth of a complicated system from a safer position.

At the end, you can install this utility from the GitHub by using gem command like this.

pre>>
% sudo gem sources -a http://gems.github.com
% sudo gem install genki-wormhole
<<--

Have fun!

posted by takiuchi takiuchi on Sat 5 Jul 2008 at 01:51 with 2 comments

以前笹田さんに、procのソースが見たいとお願いしてみたことがあったのですが、
それをRubyコードレベルで実現するライブラリを見つけたので紹介します。

proc_source.rb

I wrote this a while ago and it works by extracting a proc's origin file
name and line number from its .inspect string and using the source code
(which usually does not have to be read from disc) -- it works with
procs generated in IRB, eval() calls and regular files. It does not work
from ruby -e and stuff like "foo".instance_eval "lambda {}".source
probably doesn't work either.

オリジナルはメールの添付ファイルとしてくっついているので、ソースを見たい場合は
こちらから見るといいかもしれません。

使い方はこんな感じです、

ruby>>
code = proc{puts "Hello World"}
puts code.source #=> puts "Hello World"
<<--

これは久々に面白いものを見た気がします。

posted by genki genki on Thu 3 Jul 2008 at 13:33 with 0 comments