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 Integer | |
| include Enumerable | |
| def each(&blk) | |
| times(&blk) | |
| end | |
| end | |
| if __FILE__ == $PROGRAM_NAME | |
| require "test/unit" |
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 Object | |
| def self.void funcname, &func | |
| define_method(funcname) { |*args| func.call(*args); nil } | |
| end | |
| end | |
| if __FILE__ == $PROGRAM_NAME | |
| require "test/unit" | |
| class SampleClass | |
| void :homuhomu do |str| | |
| $str = str |
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 -*- | |
| def Object.defun(symbol, *signature, &blk) | |
| instance_variable_set(:@overloaded_methods, {}) if @overloaded_methods.nil? | |
| klass = self | |
| unless @overloaded_methods.key? symbol | |
| @overloaded_methods[symbol] = {} | |
| # super()を使ったり、実際のメソッドと同じ挙動にするにはdefine_methodを使うしかないので | |
| overload = Proc.new { |*args| | |
| oms = klass.instance_variable_get(:@overloaded_methods) | |
| sig = Signature.new(*args) |
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 Class | |
| def iffattrs *attrs | |
| define_method(:==) do |other| | |
| attrs.each do |attr| | |
| symbol = :"@#{attr}" | |
| return false if instance_variable_get(symbol) != other.instance_variable_get(symbol) | |
| end | |
| true | |
| 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 iffattrs(cls, *attrs): | |
| def _iffattrs(self, other): | |
| for name in attrs: | |
| if not hasattr(self, name) or not hasattr(other, name): | |
| return False | |
| if getattr(self, name) != getattr(other, name): | |
| return False | |
| return True | |
| cls.__eq__ = _iffattrs |
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 より後に定義する | |
| # これより前に定義されたあらゆるrequireが失敗した場合、パスの名前をwinに変えてリトライする | |
| module Kernel | |
| alias win_path_original_require require | |
| def require path | |
| win_path_original_require path | |
| rescue LoadError => e | |
| win_path_original_require to_win_path path |
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 Class | |
| def initbefore &process | |
| allocate.tap do |instance| | |
| instance.instance_eval &process | |
| end | |
| 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
| class Array | |
| alias defarray_original_at [] | |
| alias defarray_original_initialize initialize | |
| def initialize *args, &blk | |
| return defarray_original_initialize(*args, &blk) unless args.empty? | |
| @default_handler = blk | |
| 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
| # -*- coding: utf-8 -*- | |
| module Kernel | |
| def method_missing funcname, *args, &blk | |
| if funcname =~ /\A画面に「(.*)」と表示してくださいですわ\z/ | |
| puts $1 | |
| else | |
| super | |
| 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
| # -*- coding: utf-8 -*- | |
| class SynchronizedIterator | |
| include Enumerable | |
| def initialize *enumerables | |
| @enumerables = enumerables.map do |e| | |
| e.map { |item| item } | |
| end |