- Ruby で型を定義する
- 現状は Class = 型とする
- 型チェックを行う仕組み
- ジェネリックプログラミングや Variant 型(Haskell の Either みたいなの?)の定義
- C++ の template みたいなのもほしい
- 型によって処理を切り替える装置
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 call_one &block | |
| flag = false | |
| proc { flag || instance_eval(&block); flag = true } | |
| end | |
| class X | |
| define_method(:initialize, &call_one do | |
| p "homu" | |
| 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 Module | |
| def sticher_accessor **opt | |
| opt.each { |name, type| | |
| if type.class == Class | |
| # value = type.new | |
| value = nil | |
| else | |
| value = type | |
| type = type.class | |
| 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 let **opt, &block | |
| Object.new.instance_eval do | |
| for name, type in opt | |
| if type.class == Class | |
| value = type.new | |
| else | |
| tyep = type.class | |
| value = type | |
| 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 X | |
| def self.concept name, &request | |
| impl_name = "#{name}_#{request}" | |
| alias_method impl_name, name | |
| @@concept_methods ||= {} | |
| @@concept_methods[name] ||= [] | |
| @@concept_methods[name].unshift [request, impl_name] | |
| define_method(name){ |*args| | |
| for request, name_ in @@concept_methods[name] |
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
| ## 材料 | |
| * 玉ねぎ(半分をみじん切り) | |
| * にんにく(好みで) | |
| * コンソメ1つ(お湯で溶かしておく) | |
| * お湯(やかん等で沸かしておく) | |
| * 生米(2合、洗わない) | |
| * 胡椒 | |
| * オリーブオイル |
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 MethodWrapper | |
| def wrap name, &block | |
| prepend(Module.new do | |
| define_method name do | |
| super_ = proc { super() } | |
| Object.new.instance_eval do | |
| define_singleton_method :super_ do | |
| super_.() | |
| end | |
| instance_eval &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
| class Base | |
| def homu | |
| p :base | |
| end | |
| end | |
| class Derived < Base | |
| def super | |
| p :super | |
| 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
| module MethodWrapper | |
| def wrap name, &block | |
| prepend(Module.new do | |
| define_method name do | |
| super_ = proc { super() } | |
| Object.new.instance_eval do | |
| define_singleton_method :super_ do | |
| super_.() | |
| end | |
| instance_eval &block |