This file contains hidden or 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 -*- | |
| # Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
| # 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
| # Ruby1.9.3で動作確認済み | |
| # 再帰の例にあったやつを数指定可能に。根っこはひねる余地なさげ | |
| $VERBOSE = true |
This file contains hidden or 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 -*- | |
| # Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
| # 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
| # Ruby1.9.3で動作確認済み | |
| # 再帰の例に「良い例」としてあったやつなんだけど、Rubyでそのままは無理やり感が強かった。 | |
| # 再帰でシンプルに書ける理由として、ここでは「配列の長さに基づくループとか出来無いよね」という前提にたってるみたいなので・・・ | |
| $VERBOSE = true |
This file contains hidden or 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 -*- | |
| # Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
| # 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
| # Ruby1.9.3で動作確認済み | |
| # スタックの項より、標準入力から受け付けた括弧の対応を調べるスクリプト。 | |
| # 理屈は聞いたことあったけど、書くの初めてだった。 | |
| # 使い方の方が主に感じたので、Stackの実装側は委譲で済ませた。 |
This file contains hidden or 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 -*- | |
| # Cで書かれたアルゴリズムやらデータ構造なりを、自分なりにRubyで表現してみるお勉強PJ。 | |
| # 参考書籍(プログラミングの宝箱 アルゴリズムとデータ構造) | |
| # Ruby1.9.3で動作確認済み | |
| # 説明書きだけみてコーディングにトライしているので、意図を汲み取れているか微妙 | |
| # 多分木化時に再調整するなりしてまとめ直したい | |
| $VERBOSE = true |
This file contains hidden or 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
| class Module | |
| module Deprecatable | |
| def deprecated(name, options={}) | |
| older = :"_deprecated_#{name}" | |
| alias_method older, name | |
| private older | |
| define_method name do |*args, &block| | |
| warn "#{__FILE__}:#{__LINE__}:WARN #{self.class}##{name} was deprecated, use new API #{self.class}##{options[:newer]}" | |
| __send__ older, *args, &block |
This file contains hidden or 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
| $VERBOSE = true | |
| require 'kramdown' | |
| HTML_HEADER = '<head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <link href="markdown.css" rel="stylesheet"></link> | |
| </head>'.freeze | |
| abort 'usage: this.rb doc1.md [doc2.md ...docN.md]' unless ARGV.length >= 1 |
This file contains hidden or 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
| require 'ipaddr' | |
| class IPAddr | |
| #==なら要件を満たせるので、オーバーライドしてしまおう。 | |
| alias_method :'eql?', :'==' | |
| #hashの判定は、ライブラリの==メソッドから適当に判断した。 | |
| def hash | |
| [@family, @addr].hash | |
| end |
This file contains hidden or 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
| class OrderdHash | |
| extend Forwardable | |
| extend Container | |
| include Enumerable | |
| def initialize(keys=[], content={}) | |
| @keys, @content = keys, content | |
| end | |
| def_delegator :@keys, :each, :each_key |
This file contains hidden or 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
| module Container | |
| def define | |
| new.tap{|obj|yield obj} | |
| end | |
| end |
This file contains hidden or 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 mkdir(path) | |
| Dir.mkdir path unless File.exist? path | |
| end |