コードリーディング、ActiveSupport 3.2 を中心として
#railstokyo コードリーディング、ActiveSupport 3.2 を中心として
posted at 13:32:39
#railstokyo コードリーディング: aiming http://t.co/ggmrGfcP さんがリリースノート訳されてましたよね
posted at 13:34:37
#railstokyo コードリーディング: メソッドを見てくか、実装を読んでくか。実装を読む方向で
posted at 13:35:46
#railstokyo コードリーディング: http://t.co/Y73GP0Mn よりアクティブサポートの節を確認
posted at 13:37:24
#railstokyo コードリーディング: rails のソースコードはどこにあるのか、GitHub に行って下さい。そのまま読むのも良いけど、取ってきて読むのがお勧め
posted at 13:40:27
#railstokyo コードリーディング: 「git clone https://t.co/3TfuLZ36」 みんながいっぺんに取りいくと大変
posted at 13:41:55
#railstokyo コードリーディング: みんなで 3.2.1 の activesupport を
posted at 13:45:13
#railstokyo コードリーディング: アクティブなんちゃらとかアクションなんとかのディレクトリ構造、bin lib があって、lib の下にその名の rb とその名のディレクトリがあり、ディレクトリの下には……
posted at 13:50:53
その名の.rbファイルはその名のディレクトリ以下を取ってきて(require)まとめる感じ。
その名のディレクトリ以下には各機能を複数のファイルに分けて、またサブディレクトリも執り。
#railstokyo コードリーディング: ActiveSupport:TaggedLogging
posted at 13:54:52
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb
#railstokyo コードリーディング: ruby の標準アイテムをいじるときは core_ext の下とかにあります
posted at 14:04:13
#railstokyo コードリーディング: beginning_of_week メソッド、activesupport / lib / active_support / core_ext / date / calculations.rb
posted at 14:06:06
#railstokyo コードリーディング: ■ActiveSupport::Notifications.subscribed
posted at 14:09:36
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/notifications.rb
#railstokyo コードリーディング: ■ActiveSupport::Notification 、3 から来た何か、通知系?
posted at 14:12:43
#railstokyo コードリーディング: Module#qualified_const_云々
posted at 14:13:30
#railstokyo コードリーディング: Module#qualified_const_云々。::始まりを排除するわけが分かった、const_get でっ取ってこれない
posted at 14:22:42
その後 @n0kada さんよりトップレベルの定数は Object の下にあるとの指摘。まあそうはいってもこのコードでそこを別処理するのは無理あるかな
https://twitter.com/n0kada/status/170759579003658241
#railstokyo コードリーディング: #demodulize と対になる #deconstantize
posted at 14:23:22
#railstokyo コードリーディング: activesupport / lib / active_support / inflector
posted at 14:25:45
#railstokyo コードリーディング: safe_constantize 、これも inflector
posted at 14:26:43
#railstokyo コードリーディング: safe_constantize 、safeといっても危険なときにはエラーを raise する。
posted at 14:31:32
rescue NameError => e raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ || e.name.to_s == camel_cased_word.to_s rescue ArgumentError => e raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/ end
どんなときに raise するか見ておく
#railstokyo コードリーディング: なんか mさんのコードリーディングのやり方講座、みたいな
posted at 14:32:11