public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Inline code comments for class_eval/module_eval [#1657 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
fxn (author)
Sun Dec 28 11:48:05 -0800 2008
lifo (committer)
Sun Dec 28 11:49:28 -0800 2008
commit  a2270ef2594b97891994848138614657363f2806
tree    29962a36c4eb70272df2665db2b28d5b3ad15b99
parent  1fb275541a58e6a2100261c6117e96e6c014cc6c
...
163
164
165
166
167
168
 
 
 
169
170
171
...
163
164
165
 
 
 
166
167
168
169
170
171
0
@@ -163,9 +163,9 @@ module ActionController #:nodoc:
0
       def helper_method(*methods)
0
         methods.flatten.each do |method|
0
           master_helper_module.module_eval <<-end_eval
0
-            def #{method}(*args, &block)
0
-              controller.send(%(#{method}), *args, &block)
0
-            end
0
+            def #{method}(*args, &block)                    # def current_user(*args, &block)
0
+              controller.send(%(#{method}), *args, &block)  #   controller.send(%(current_user), *args, &block)
0
+            end                                             # end
0
           end_eval
0
         end
0
       end
...
148
149
150
151
152
153
 
 
 
154
155
156
...
148
149
150
 
 
 
151
152
153
154
155
156
0
@@ -148,9 +148,9 @@ module ActionController #:nodoc:
0
         sym = mime.is_a?(Symbol) ? mime : mime.to_sym
0
         const = sym.to_s.upcase
0
         class_eval <<-RUBY, __FILE__, __LINE__ + 1
0
-          def #{sym}(&block)                          # def html(&block)
0
-            custom(Mime::#{const}, &block)            #   custom(Mime::HTML, &block)
0
-          end                                         # end
0
+          def #{sym}(&block)                # def html(&block)
0
+            custom(Mime::#{const}, &block)  #   custom(Mime::HTML, &block)
0
+          end                               # end
0
         RUBY
0
       end
0
 
...
118
119
120
121
122
123
124
125
126
127
 
 
 
 
 
 
 
 
 
 
 
128
129
130
...
118
119
120
 
 
 
 
 
 
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -118,13 +118,17 @@ module ActionController
0
 
0
     %w(edit new).each do |action|
0
       module_eval <<-EOT, __FILE__, __LINE__
0
-        def #{action}_polymorphic_url(record_or_hash, options = {})
0
-          polymorphic_url(record_or_hash, options.merge(:action => "#{action}"))
0
-        end
0
-
0
-        def #{action}_polymorphic_path(record_or_hash, options = {})
0
-          polymorphic_url(record_or_hash, options.merge(:action => "#{action}", :routing_type => :path))
0
-        end
0
+        def #{action}_polymorphic_url(record_or_hash, options = {})         # def edit_polymorphic_url(record_or_hash, options = {})
0
+          polymorphic_url(                                                  #   polymorphic_url(
0
+            record_or_hash,                                                 #     record_or_hash,
0
+            options.merge(:action => "#{action}"))                          #     options.merge(:action => "edit"))
0
+        end                                                                 # end
0
+                                                                            #
0
+        def #{action}_polymorphic_path(record_or_hash, options = {})        # def edit_polymorphic_path(record_or_hash, options = {})
0
+          polymorphic_url(                                                  #   polymorphic_url(
0
+            record_or_hash,                                                 #     record_or_hash,
0
+            options.merge(:action => "#{action}", :routing_type => :path))  #     options.merge(:action => "edit", :routing_type => :path))
0
+        end                                                                 # end
0
       EOT
0
     end
0
 
...
145
146
147
148
149
150
151
 
 
 
 
152
153
154
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
203
204
...
145
146
147
 
 
 
 
148
149
150
151
152
153
154
...
173
174
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
0
@@ -145,10 +145,10 @@ module ActionController
0
           def define_hash_access(route, name, kind, options)
0
             selector = hash_access_name(name, kind)
0
             named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
0
-              def #{selector}(options = nil)
0
-                options ? #{options.inspect}.merge(options) : #{options.inspect}
0
-              end
0
-              protected :#{selector}
0
+              def #{selector}(options = nil)                                      # def hash_for_users_url(options = nil)
0
+                options ? #{options.inspect}.merge(options) : #{options.inspect}  #   options ? {:only_path=>false}.merge(options) : {:only_path=>false}
0
+              end                                                                 # end
0
+              protected :#{selector}                                              # protected :hash_for_users_url
0
             end_eval
0
             helpers << selector
0
           end
0
@@ -173,32 +173,33 @@ module ActionController
0
             #   foo_url(bar, baz, bang, :sort_by => 'baz')
0
             #
0
             named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
0
-              def #{selector}(*args)
0
-
0
-                #{generate_optimisation_block(route, kind)}
0
-
0
-                opts = if args.empty? || Hash === args.first
0
-                  args.first || {}
0
-                else
0
-                  options = args.extract_options!
0
-                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|
0
-                    h[k] = v
0
-                    h
0
-                  end
0
-                  options.merge(args)
0
-                end
0
-
0
-                url_for(#{hash_access_method}(opts))
0
-                
0
-              end
0
-              #Add an alias to support the now deprecated formatted_* URL.
0
-              def formatted_#{selector}(*args)
0
-                ActiveSupport::Deprecation.warn(
0
-                  "formatted_#{selector}() has been deprecated. please pass format to the standard" +
0
-                  "#{selector}() method instead.", caller)
0
-                #{selector}(*args)
0
-              end
0
-              protected :#{selector}
0
+              def #{selector}(*args)                                                        # def users_url(*args)
0
+                                                                                            #
0
+                #{generate_optimisation_block(route, kind)}                                 #   #{generate_optimisation_block(route, kind)}
0
+                                                                                            #
0
+                opts = if args.empty? || Hash === args.first                                #   opts = if args.empty? || Hash === args.first
0
+                  args.first || {}                                                          #     args.first || {}
0
+                else                                                                        #   else
0
+                  options = args.extract_options!                                           #     options = args.extract_options!
0
+                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|  #     args = args.zip([]).inject({}) do |h, (v, k)|
0
+                    h[k] = v                                                                #       h[k] = v
0
+                    h                                                                       #       h
0
+                  end                                                                       #     end
0
+                  options.merge(args)                                                       #     options.merge(args)
0
+                end                                                                         #   end
0
+                                                                                            #
0
+                url_for(#{hash_access_method}(opts))                                        #   url_for(hash_for_users_url(opts))
0
+                                                                                            #
0
+              end                                                                           # end
0
+              #Add an alias to support the now deprecated formatted_* URL.                  # #Add an alias to support the now deprecated formatted_* URL.
0
+              def formatted_#{selector}(*args)                                              # def formatted_users_url(*args)
0
+                ActiveSupport::Deprecation.warn(                                            #   ActiveSupport::Deprecation.warn(
0
+                  "formatted_#{selector}() has been deprecated. " +                         #     "formatted_users_url() has been deprecated. " +
0
+                  "please pass format to the standard" +                                    #     "please pass format to the standard" +
0
+                  "#{selector}() method instead.", caller)                                  #     "users_url() method instead.", caller)
0
+                #{selector}(*args)                                                          #   users_url(*args)
0
+              end                                                                           # end
0
+              protected :#{selector}                                                        # protected :users_url
0
             end_eval
0
             helpers << selector
0
           end
...
737
738
739
740
741
742
 
 
 
 
 
 
 
743
744
745
...
737
738
739
 
 
 
740
741
742
743
744
745
746
747
748
749
0
@@ -737,9 +737,13 @@ module ActionView
0
 
0
       (field_helpers - %w(label check_box radio_button fields_for)).each do |selector|
0
         src = <<-end_src
0
-          def #{selector}(method, options = {})
0
-            @template.send(#{selector.inspect}, @object_name, method, objectify_options(options))
0
-          end
0
+          def #{selector}(method, options = {})  # def text_field(method, options = {})
0
+            @template.send(                      #   @template.send(
0
+              #{selector.inspect},               #     "text_field",
0
+              @object_name,                      #     @object_name,
0
+              method,                            #     method,
0
+              objectify_options(options))        #     objectify_options(options))
0
+          end                                    # end
0
         end_src
0
         class_eval src, __FILE__, __LINE__
0
       end
...
1216
1217
1218
1219
1220
1221
1222
1223
 
 
 
 
 
1224
1225
1226
...
1463
1464
1465
1466
1467
1468
1469
1470
1471
 
 
 
 
 
 
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
 
 
 
 
 
 
 
1482
1483
1484
...
1216
1217
1218
 
 
 
 
 
1219
1220
1221
1222
1223
1224
1225
1226
...
1463
1464
1465
 
 
 
 
 
 
1466
1467
1468
1469
1470
1471
1472
1473
1474
 
 
 
 
 
 
 
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
0
@@ -1216,11 +1216,11 @@ module ActiveRecord
0
         # callbacks will be executed after the association is wiped out.
0
         old_method = "destroy_without_habtm_shim_for_#{reflection.name}"
0
         class_eval <<-end_eval unless method_defined?(old_method)
0
-          alias_method :#{old_method}, :destroy_without_callbacks
0
-          def destroy_without_callbacks
0
-            #{reflection.name}.clear
0
-            #{old_method}
0
-          end
0
+          alias_method :#{old_method}, :destroy_without_callbacks  # alias_method :destroy_without_habtm_shim_for_posts, :destroy_without_callbacks
0
+          def destroy_without_callbacks                            # def destroy_without_callbacks
0
+            #{reflection.name}.clear                               #   posts.clear
0
+            #{old_method}                                          #   destroy_without_habtm_shim_for_posts
0
+          end                                                      # end
0
         end_eval
0
 
0
         add_association_callbacks(reflection.name, options)
0
@@ -1463,22 +1463,22 @@ module ActiveRecord
0
                 before_destroy method_name
0
               when :delete_all
0
                 module_eval %Q{
0
-                  before_destroy do |record|
0
-                    delete_all_has_many_dependencies(record,
0
-                      "#{reflection.name}",
0
-                      #{reflection.class_name},
0
-                      %@#{dependent_conditions}@)
0
-                  end
0
+                  before_destroy do |record|                  # before_destroy do |record|
0
+                    delete_all_has_many_dependencies(record,  #   delete_all_has_many_dependencies(record,
0
+                      "#{reflection.name}",                   #     "posts",
0
+                      #{reflection.class_name},               #     Post,
0
+                      %@#{dependent_conditions}@)             #     %@...@) # this is a string literal like %(...)
0
+                  end                                         # end
0
                 }
0
               when :nullify
0
                 module_eval %Q{
0
-                  before_destroy do |record|
0
-                    nullify_has_many_dependencies(record,
0
-                      "#{reflection.name}",
0
-                      #{reflection.class_name},
0
-                      "#{reflection.primary_key_name}",
0
-                      %@#{dependent_conditions}@)
0
-                  end
0
+                  before_destroy do |record|                  # before_destroy do |record|
0
+                    nullify_has_many_dependencies(record,     #   nullify_has_many_dependencies(record,
0
+                      "#{reflection.name}",                   #     "posts",
0
+                      #{reflection.class_name},               #     Post,
0
+                      "#{reflection.primary_key_name}",       #     "user_id",
0
+                      %@#{dependent_conditions}@)             #     %@...@) # this is a string literal like %(...)
0
+                  end                                         # end
0
                 }
0
               else
0
                 raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, or :nullify (#{reflection.options[:dependent].inspect})"
...
1818
1819
1820
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1821
1822
1823
1824
 
 
 
 
1825
1826
1827
...
1839
1840
1841
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1842
1843
1844
...
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
 
1842
1843
1844
1845
1846
1847
1848
...
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
0
@@ -1818,10 +1818,31 @@ module ActiveRecord #:nodoc:
0
             if match.finder?
0
               finder = match.finder
0
               bang = match.bang?
0
+              # def self.find_by_login_and_activated(*args)
0
+              #   options = args.extract_options!
0
+              #   attributes = construct_attributes_from_arguments(
0
+              #     [:login,:activated],
0
+              #     args
0
+              #   )
0
+              #   finder_options = { :conditions => attributes }
0
+              #   validate_find_options(options)
0
+              #   set_readonly_option!(options)
0
+              #
0
+              #   if options[:conditions]
0
+              #     with_scope(:find => finder_options) do
0
+              #       find(:first, options)
0
+              #     end
0
+              #   else
0
+              #     find(:first, options.merge(finder_options))
0
+              #   end
0
+              # end
0
               self.class_eval %{
0
                 def self.#{method_id}(*args)
0
                   options = args.extract_options!
0
-                  attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
0
+                  attributes = construct_attributes_from_arguments(
0
+                    [:#{attribute_names.join(',:')}],
0
+                    args
0
+                  )
0
                   finder_options = { :conditions => attributes }
0
                   validate_find_options(options)
0
                   set_readonly_option!(options)
0
@@ -1839,6 +1860,31 @@ module ActiveRecord #:nodoc:
0
               send(method_id, *arguments)
0
             elsif match.instantiator?
0
               instantiator = match.instantiator
0
+              # def self.find_or_create_by_user_id(*args)
0
+              #   guard_protected_attributes = false
0
+              #
0
+              #   if args[0].is_a?(Hash)
0
+              #     guard_protected_attributes = true
0
+              #     attributes = args[0].with_indifferent_access
0
+              #     find_attributes = attributes.slice(*[:user_id])
0
+              #   else
0
+              #     find_attributes = attributes = construct_attributes_from_arguments([:user_id], args)
0
+              #   end
0
+              #
0
+              #   options = { :conditions => find_attributes }
0
+              #   set_readonly_option!(options)
0
+              #
0
+              #   record = find(:first, options)
0
+              #
0
+              #   if record.nil?
0
+              #     record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
0
+              #     yield(record) if block_given?
0
+              #     record.save
0
+              #     record
0
+              #   else
0
+              #     record
0
+              #   end
0
+              # end
0
               self.class_eval %{
0
                 def self.#{method_id}(*args)
0
                   guard_protected_attributes = false
...
14
15
16
17
18
19
20
21
22
 
 
 
 
 
 
23
24
25
...
14
15
16
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
0
@@ -14,12 +14,12 @@ module ActiveRecord
0
         def dirties_query_cache(base, *method_names)
0
           method_names.each do |method_name|
0
             base.class_eval <<-end_code, __FILE__, __LINE__
0
-              def #{method_name}_with_query_dirty(*args)
0
-                clear_query_cache if @query_cache_enabled
0
-                #{method_name}_without_query_dirty(*args)
0
-              end
0
-
0
-              alias_method_chain :#{method_name}, :query_dirty
0
+              def #{method_name}_with_query_dirty(*args)        # def update_with_query_dirty(*args)
0
+                clear_query_cache if @query_cache_enabled       #   clear_query_cache if @query_cache_enabled
0
+                #{method_name}_without_query_dirty(*args)       #   update_without_query_dirty(*args)
0
+              end                                               # end
0
+                                                                #
0
+              alias_method_chain :#{method_name}, :query_dirty  # alias_method_chain :update, :query_dirty
0
             end_code
0
           end
0
         end
...
476
477
478
479
480
481
482
483
484
 
 
 
 
 
 
485
486
487
...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
697
698
699
...
476
477
478
 
 
 
 
 
 
479
480
481
482
483
484
485
486
487
...
676
677
678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
0
@@ -476,12 +476,12 @@ module ActiveRecord
0
 
0
       %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
0
         class_eval <<-EOV
0
-          def #{column_type}(*args)
0
-            options = args.extract_options!
0
-            column_names = args
0
-
0
-            column_names.each { |name| column(name, '#{column_type}', options) }
0
-          end
0
+          def #{column_type}(*args)                                               # def string(*args)
0
+            options = args.extract_options!                                       #   options = args.extract_options!
0
+            column_names = args                                                   #   column_names = args
0
+                                                                                  #
0
+            column_names.each { |name| column(name, '#{column_type}', options) }  #   column_names.each { |name| column(name, 'string', options) }
0
+          end                                                                     # end
0
         EOV
0
       end
0
 
0
@@ -676,24 +676,24 @@ module ActiveRecord
0
       #  t.string(:goat, :sheep)
0
       %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
0
         class_eval <<-EOV
0
-          def #{column_type}(*args)
0
-            options = args.extract_options!
0
-            column_names = args
0
-
0
-            column_names.each do |name|
0
-              column = ColumnDefinition.new(@base, name, '#{column_type}')
0
-              if options[:limit]
0
-                column.limit = options[:limit]
0
-              elsif native['#{column_type}'.to_sym].is_a?(Hash)
0
-                column.limit = native['#{column_type}'.to_sym][:limit]
0
-              end
0
-              column.precision = options[:precision]
0
-              column.scale = options[:scale]
0
-              column.default = options[:default]
0
-              column.null = options[:null]
0
-              @base.add_column(@table_name, name, column.sql_type, options)
0
-            end
0
-          end
0
+          def #{column_type}(*args)                                          # def string(*args)
0
+            options = args.extract_options!                                  #   options = args.extract_options!
0
+            column_names = args                                              #   column_names = args
0
+                                                                             #
0
+            column_names.each do |name|                                      #   column_names.each do |name|
0
+              column = ColumnDefinition.new(@base, name, '#{column_type}')   #     column = ColumnDefinition.new(@base, name, 'string')
0
+              if options[:limit]                                             #     if options[:limit]
0
+                column.limit = options[:limit]                               #       column.limit = options[:limit]
0
+              elsif native['#{column_type}'.to_sym].is_a?(Hash)              #     elsif native['string'.to_sym].is_a?(Hash)
0
+                column.limit = native['#{column_type}'.to_sym][:limit]       #       column.limit = native['string'.to_sym][:limit]
0
+              end                                                            #     end
0
+              column.precision = options[:precision]                         #     column.precision = options[:precision]
0
+              column.scale = options[:scale]                                 #     column.scale = options[:scale]
0
+              column.default = options[:default]                             #     column.default = options[:default]
0
+              column.null = options[:null]                                   #     column.null = options[:null]
0
+              @base.add_column(@table_name, name, column.sql_type, options)  #     @base.add_column(@table_name, name, column.sql_type, options)
0
+            end                                                              #   end
0
+          end                                                                # end
0
         EOV
0
       end
0
 
...
13
14
15
16
17
18
19
20
 
 
 
 
 
21
22
23
24
25
26
27
28
29
30
31
32
 
 
 
 
 
 
 
 
33
34
35
...
13
14
15
 
 
 
 
 
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
27
28
29
30
31
32
33
34
35
36
37
0
@@ -13,23 +13,25 @@ module MysqlCompat #:nodoc:
0
     # C driver >= 2.7 returns null values in each_hash
0
     if Mysql.const_defined?(:VERSION) && (Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700)
0
       target.class_eval <<-'end_eval'
0
-      def all_hashes
0
-        rows = []
0
-        each_hash { |row| rows << row }
0
-        rows
0
-      end
0
+      def all_hashes                     # def all_hashes
0
+        rows = []                        #   rows = []
0
+        each_hash { |row| rows << row }  #   each_hash { |row| rows << row }
0
+        rows                             #   rows
0
+      end                                # end
0
       end_eval
0
 
0
     # adapters before 2.7 don't have a version constant
0
     # and don't return null values in each_hash
0
     else
0
       target.class_eval <<-'end_eval'
0
-      def all_hashes
0
-        rows = []
0
-        all_fields = fetch_fields.inject({}) { |fields, f| fields[f.name] = nil; fields }
0
-        each_hash { |row| rows << all_fields.dup.update(row) }
0
-        rows
0
-      end
0
+      def all_hashes                                            # def all_hashes
0
+        rows = []                                               #   rows = []
0
+        all_fields = fetch_fields.inject({}) { |fields, f|      #   all_fields = fetch_fields.inject({}) { |fields, f|
0
+          fields[f.name] = nil; fields                          #     fields[f.name] = nil; fields
0
+        }                                                       #   }
0
+        each_hash { |row| rows << all_fields.dup.update(row) }  #   each_hash { |row| rows << all_fields.dup.update(row) }
0
+        rows                                                    #   rows
0
+      end                                                       # end
0
       end_eval
0
     end
0
 
...
950
951
952
953
954
955
956
957
958
959
 
 
 
 
 
 
 
960
961
962
...
950
951
952
 
 
 
 
 
 
 
953
954
955
956
957
958
959
960
961
962
0
@@ -950,13 +950,13 @@ module ActiveRecord
0
           # should know about this but can't detect it there, so deal with it here.
0
           money_precision = (postgresql_version >= 80300) ? 19 : 10
0
           PostgreSQLColumn.module_eval(<<-end_eval)
0
-            def extract_precision(sql_type)
0
-              if sql_type =~ /^money$/
0
-                #{money_precision}
0
-              else
0
-                super
0
-              end
0
-            end
0
+            def extract_precision(sql_type)  # def extract_precision(sql_type)
0
+              if sql_type =~ /^money$/       #   if sql_type =~ /^money$/
0
+                #{money_precision}           #     19
0
+              else                           #   else
0
+                super                        #     super
0
+              end                            #   end
0
+            end                              # end
0
           end_eval
0
 
0
           configure_connection
...
174
175
176
177
 
178
179
180
...
174
175
176
 
177
178
179
180
0
@@ -174,7 +174,7 @@ module ActiveRecord
0
         alias_attribute_without_dirty(new_name, old_name)
0
         DIRTY_SUFFIXES.each do |suffix|
0
           module_eval <<-STR, __FILE__, __LINE__+1
0
-            def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end
0
+            def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end  # def subject_changed?; self.title_changed?; end
0
           STR
0
         end
0
       end
...
54
55
56
 
 
 
57
58
59
...
118
119
120
 
 
 
 
 
121
122
123
...
54
55
56
57
58
59
60
61
62
...
121
122
123
124
125
126
127
128
129
130
131
0
@@ -54,6 +54,9 @@ module ActiveResource
0
       end
0
 
0
       for method in [ :post, :put, :get, :delete, :head ]
0
+        # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
0
+        #   @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
0
+        # end
0
         module_eval <<-EOE, __FILE__, __LINE__
0
           def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
0
             @responses[Request.new(:#{method}, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
0
@@ -118,6 +121,11 @@ module ActiveResource
0
     end
0
 
0
     for method in [ :post, :put ]
0
+      # def post(path, body, headers)
0
+      #   request = ActiveResource::Request.new(:post, path, body, headers)
0
+      #   self.class.requests << request
0
+      #   self.class.responses[request] || raise(InvalidRequestError.new("No response recorded for #{request}"))
0
+      # end
0
       module_eval <<-EOE, __FILE__, __LINE__
0
         def #{method}(path, body, headers)
0
           request = ActiveResource::Request.new(:#{method}, path, body, headers)
...
68
69
70
71
72
73
74
75
76
77
 
 
 
 
 
 
 
78
79
80
...
68
69
70
 
 
 
 
 
 
 
71
72
73
74
75
76
77
78
79
80
0
@@ -68,13 +68,13 @@ module ActiveSupport
0
 
0
     for severity in Severity.constants
0
       class_eval <<-EOT, __FILE__, __LINE__
0
-        def #{severity.downcase}(message = nil, progname = nil, &block)
0
-          add(#{severity}, message, progname, &block)
0
-        end
0
-
0
-        def #{severity.downcase}?
0
-          #{severity} >= @level
0
-        end
0
+        def #{severity.downcase}(message = nil, progname = nil, &block)  # def debug(message = nil, progname = nil, &block)
0
+          add(#{severity}, message, progname, &block)                    #   add(DEBUG, message, progname, &block)
0
+        end                                                              # end
0
+                                                                         #
0
+        def #{severity.downcase}?                                        # def debug?
0
+          #{severity} >= @level                                          #   DEBUG >= @level
0
+        end                                                              # end
0
       EOT
0
     end
0
 
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
228
229
...
210
211
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
0
@@ -210,20 +210,24 @@ module ActiveSupport
0
       def define_callbacks(*callbacks)
0
         callbacks.each do |callback|
0
           class_eval <<-"end_eval"
0
-            def self.#{callback}(*methods, &block)
0
-              callbacks = CallbackChain.build(:#{callback}, *methods, &block)
0
-              (@#{callback}_callbacks ||= CallbackChain.new).concat callbacks
0
-            end
0
-
0
-            def self.#{callback}_callback_chain
0
-              @#{callback}_callbacks ||= CallbackChain.new
0
-
0
-              if superclass.respond_to?(:#{callback}_callback_chain)
0
-                CallbackChain.new(superclass.#{callback}_callback_chain + @#{callback}_callbacks)
0
-              else
0
-                @#{callback}_callbacks
0
-              end
0
-            end
0
+            def self.#{callback}(*methods, &block)                             # def self.before_save(*methods, &block)
0
+              callbacks = CallbackChain.build(:#{callback}, *methods, &block)  #   callbacks = CallbackChain.build(:before_save, *methods, &block)
0
+              @#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new
0
+              @#{callback}_callbacks.concat callbacks                          #   @before_save_callbacks.concat callbacks
0
+            end                                                                # end
0
+                                                                               #
0
+            def self.#{callback}_callback_chain                                # def self.before_save_callback_chain
0
+              @#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new
0
+                                                                               #
0
+              if superclass.respond_to?(:#{callback}_callback_chain)           #   if superclass.respond_to?(:before_save_callback_chain)
0
+                CallbackChain.new(                                             #     CallbackChain.new(
0
+                  superclass.#{callback}_callback_chain +                      #       superclass.before_save_callback_chain +
0
+                  @#{callback}_callbacks                                       #       @before_save_callbacks
0
+                )                                                              #     )
0
+              else                                                             #   else
0
+                @#{callback}_callbacks                                         #     @before_save_callbacks
0
+              end                                                              #   end
0
+            end                                                                # end
0
           end_eval
0
         end
0
       end
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
25
26
27
...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
...
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -11,17 +11,17 @@ class Class
0
     syms.flatten.each do |sym|
0
       next if sym.is_a?(Hash)
0
       class_eval(<<-EOS, __FILE__, __LINE__)
0
-        unless defined? @@#{sym}
0
-          @@#{sym} = nil
0
-        end
0
-
0
-        def self.#{sym}
0
-          @@#{sym}
0
-        end
0
-
0
-        def #{sym}
0
-          @@#{sym}
0
-        end
0
+        unless defined? @@#{sym}  # unless defined? @@hair_colors
0
+          @@#{sym} = nil          #   @@hair_colors = nil
0
+        end                       # end
0
+                                  #
0
+        def self.#{sym}           # def self.hair_colors
0
+          @@#{sym}                #   @@hair_colors
0
+        end                       # end
0
+                                  #
0
+        def #{sym}                # def hair_colors
0
+          @@#{sym}                #   @@hair_colors
0
+        end                       # end
0
       EOS
0
     end
0
   end
0
@@ -30,19 +30,19 @@ class Class
0
     options = syms.extract_options!
0
     syms.flatten.each do |sym|
0
       class_eval(<<-EOS, __FILE__, __LINE__)
0
-        unless defined? @@#{sym}
0
-          @@#{sym} = nil
0
-        end
0
-
0
-        def self.#{sym}=(obj)
0
-          @@#{sym} = obj
0
-        end
0
-
0
-        #{"
0
-        def #{sym}=(obj)
0
-          @@#{sym} = obj
0
-        end
0
-        " unless options[:instance_writer] == false }
0
+        unless defined? @@#{sym}                       # unless defined? @@hair_colors
0
+          @@#{sym} = nil                               #   @@hair_colors = nil
0
+        end                                            # end
0
+                                                       #
0
+        def self.#{sym}=(obj)                          # def self.hair_colors=(obj)
0
+          @@#{sym} = obj                               #   @@hair_colors = obj
0
+        end                                            # end
0
+                                                       #
0
+        #{"                                            #
0
+        def #{sym}=(obj)                               # def hair_colors=(obj)
0
+          @@#{sym} = obj                               #   @@hair_colors = obj
0
+        end                                            # end
0
+        " unless options[:instance_writer] == false }  # # instance writer above is generated unless options[:instance_writer] == false
0
       EOS
0
     end
0
   end
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
...
32
33
34
35
36
37
 
 
 
38
39
40
...
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
33
34
35
 
 
 
36
37
38
39
40
41
0
@@ -9,22 +9,23 @@ class Class
0
     class_name_to_stop_searching_on = self.superclass.name.blank? ? "Object" : self.superclass.name
0
     names.each do |name|
0
       class_eval <<-EOS
0
-      def self.#{name}
0
-        if defined?(@#{name})
0
-          @#{name}
0
-        elsif superclass < #{class_name_to_stop_searching_on} && superclass.respond_to?(:#{name})
0
-          superclass.#{name}
0
-        end
0
-      end
0
-      def #{name}
0
-        self.class.#{name}
0
-      end
0
-      def self.#{name}?
0
-        !!#{name}
0
-      end
0
-      def #{name}?
0
-        !!#{name}
0
-      end
0
+      def self.#{name}                                            # def self.only_reader
0
+        if defined?(@#{name})                                     #   if defined?(@only_reader)
0
+          @#{name}                                                #     @only_reader
0
+        elsif superclass < #{class_name_to_stop_searching_on} &&  #   elsif superclass < Object &&
0
+              superclass.respond_to?(:#{name})                    #         superclass.respond_to?(:only_reader)
0
+          superclass.#{name}                                      #     superclass.only_reader
0
+        end                                                       #   end
0
+      end                                                         # end
0
+      def #{name}                                                 # def only_reader
0
+        self.class.#{name}                                        #   self.class.only_reader
0
+      end                                                         # end
0
+      def self.#{name}?                                           # def self.only_reader?
0
+        !!#{name}                                                 #   !!only_reader
0
+      end                                                         # end
0
+      def #{name}?                                                # def only_reader?
0
+        !!#{name}                                                 #   !!only_reader
0
+      end                                                         # end
0
       EOS
0
     end
0
   end
0
@@ -32,9 +33,9 @@ class Class
0
   def superclass_delegating_writer(*names)
0
     names.each do |name|
0
       class_eval <<-EOS
0
-        def self.#{name}=(value)
0
-          @#{name} = value
0
-        end
0
+        def self.#{name}=(value)  # def self.only_writer=(value)
0
+          @#{name} = value        #   @only_writer = value
0
+        end                       # end
0
       EOS
0
     end
0
   end
...
11
12
13
14
15
16
17
18
19
20
 
 
 
 
 
 
 
21
22
23
...
26
27
28
29
30
31
32
33
34
35
36
37
 
 
 
 
 
 
 
 
 
38
39
40
...
43
44
45
46
47
48
49
50
51
52
53
54
 
 
 
 
 
 
 
 
 
55
56
57
...
60
61
62
63
64
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
 
72
73
74
...
11
12
13
 
 
 
 
 
 
 
14
15
16
17
18
19
20
21
22
23
...
26
27
28
 
 
 
 
 
 
 
 
 
29
30
31
32
33
34
35
36
37
38
39
40
...
43
44
45
 
 
 
 
 
 
 
 
 
46
47
48
49
50
51
52
53
54
55
56
57
...
60
61
62
 
 
 
 
 
 
 
 
 
63
64
65
66
67
68
69
70
71
72
73
74
0
@@ -11,13 +11,13 @@ class Class # :nodoc:
0
     syms.each do |sym|
0
       next if sym.is_a?(Hash)
0
       class_eval <<-EOS
0
-        def self.#{sym}
0
-          read_inheritable_attribute(:#{sym})
0
-        end
0
-
0
-        def #{sym}
0
-          self.class.#{sym}
0
-        end
0
+        def self.#{sym}                        # def self.before_add_for_comments
0
+          read_inheritable_attribute(:#{sym})  #   read_inheritable_attribute(:before_add_for_comments)
0
+        end                                    # end
0
+                                               #
0
+        def #{sym}                             # def before_add_for_comments
0
+          self.class.#{sym}                    #   self.class.before_add_for_comments
0
+        end                                    # end
0
       EOS
0
     end
0
   end
0
@@ -26,15 +26,15 @@ class Class # :nodoc:
0
     options = syms.extract_options!
0
     syms.each do |sym|
0
       class_eval <<-EOS
0
-        def self.#{sym}=(obj)
0
-          write_inheritable_attribute(:#{sym}, obj)
0
-        end
0
-
0
-        #{"
0
-        def #{sym}=(obj)
0
-          self.class.#{sym} = obj
0
-        end
0
-        " unless options[:instance_writer] == false }
0
+        def self.#{sym}=(obj)                          # def self.color=(obj)
0
+          write_inheritable_attribute(:#{sym}, obj)    #   write_inheritable_attribute(:color, obj)
0
+        end                                            # end
0
+                                                       #
0
+        #{"                                            #
0
+        def #{sym}=(obj)                               # def color=(obj)
0
+          self.class.#{sym} = obj                      #   self.class.color = obj
0
+        end                                            # end
0
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
0
       EOS
0
     end
0
   end
0
@@ -43,15 +43,15 @@ class Class # :nodoc:
0
     options = syms.extract_options!
0
     syms.each do |sym|
0
       class_eval <<-EOS
0
-        def self.#{sym}=(obj)
0
-          write_inheritable_array(:#{sym}, obj)
0
-        end
0
-
0
-        #{"
0
-        def #{sym}=(obj)
0
-          self.class.#{sym} = obj
0
-        end
0
-        " unless options[:instance_writer] == false }
0
+        def self.#{sym}=(obj)                          # def self.levels=(obj)
0
+          write_inheritable_array(:#{sym}, obj)        #   write_inheritable_array(:levels, obj)
0
+        end                                            # end
0
+                                                       #
0
+        #{"                                            #
0
+        def #{sym}=(obj)                               # def levels=(obj)
0
+          self.class.#{sym} = obj                      #   self.class.levels = obj
0
+        end                                            # end
0
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
0
       EOS
0
     end
0
   end
0
@@ -60,15 +60,15 @@ class Class # :nodoc:
0
     options = syms.extract_options!
0
     syms.each do |sym|
0
       class_eval <<-EOS
0
-        def self.#{sym}=(obj)
0
-          write_inheritable_hash(:#{sym}, obj)
0
-        end
0
-
0
-        #{"
0
-        def #{sym}=(obj)
0
-          self.class.#{sym} = obj
0
-        end
0
-        " unless options[:instance_writer] == false }
0
+        def self.#{sym}=(obj)                          # def self.nicknames=(obj)
0
+          write_inheritable_hash(:#{sym}, obj)         #   write_inheritable_hash(:nicknames, obj)
0
+        end                                            # end
0
+                                                       #
0
+        #{"                                            #
0
+        def #{sym}=(obj)                               # def nicknames=(obj)
0
+          self.class.#{sym} = obj                      #   self.class.nicknames = obj
0
+        end                                            # end
0
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
0
       EOS
0
     end
0
   end
...
3
4
5
6
7
8
9
10
11
 
 
 
 
 
 
12
13
14
...
3
4
5
 
 
 
 
 
 
6
7
8
9
10
11
12
13
14
0
@@ -3,12 +3,12 @@
0
 class Logger
0
   def self.define_around_helper(level)
0
     module_eval <<-end_eval
0
-      def around_#{level}(before_message, after_message, &block)
0
-        self.#{level}(before_message)
0
-        return_value = block.call(self)
0
-        self.#{level}(after_message)
0
-        return return_value
0
-      end
0
+      def around_#{level}(before_message, after_message, &block)  # def around_debug(before_message, after_message, &block)
0
+        self.#{level}(before_message)                             #   self.debug(before_message)
0
+        return_value = block.call(self)                           #   return_value = block.call(self)
0
+        self.#{level}(after_message)                              #   self.debug(after_message)
0
+        return return_value                                       #   return return_value
0
+      end                                                         # end
0
     end_eval
0
   end
0
   [:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
...
64
65
66
67
68
69
 
 
 
70
71
72
...
64
65
66
 
 
 
67
68
69
70
71
72
0
@@ -64,9 +64,9 @@ module ActiveSupport
0
       #   e.title    # => "Megastars"
0
       def alias_attribute(new_name, old_name)
0
         module_eval <<-STR, __FILE__, __LINE__+1
0
-          def #{new_name}; self.#{old_name}; end
0
-          def #{new_name}?; self.#{old_name}?; end
0
-          def #{new_name}=(v); self.#{old_name} = v; end
0
+          def #{new_name}; self.#{old_name}; end          # def subject; self.title; end
0
+          def #{new_name}?; self.#{old_name}?; end        # def subject?; self.title?; end
0
+          def #{new_name}=(v); self.#{old_name} = v; end  # def subject=(v); self.title = v; end
0
         STR
0
       end
0
     end
...
22
23
24
25
26
27
28
 
 
 
 
29
30
31
...
22
23
24
 
 
 
 
25
26
27
28
29
30
31
0
@@ -22,10 +22,10 @@ class Module
0
     raise 'Default value or block required' unless !default.nil? || block
0
     define_method(sym, block_given? ? block : Proc.new { default })
0
     module_eval(<<-EVAL, __FILE__, __LINE__)
0
-      def #{sym}=(value)
0
-        class << self; attr_reader :#{sym} end
0
-        @#{sym} = value
0
-      end
0
+      def #{sym}=(value)                        # def age=(value)
0
+        class << self; attr_reader :#{sym} end  #   class << self; attr_reader :age end
0
+        @#{sym} = value                         #   @age = value
0
+      end                                       # end
0
     EVAL
0
   end
0
 end
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51
52
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -15,17 +15,17 @@ class Module
0
     syms.each do |sym|
0
       next if sym.is_a?(Hash)
0
       class_eval(<<-EOS, __FILE__, __LINE__)
0
-        unless defined? @@#{sym}
0
-          @@#{sym} = nil
0
-        end
0
-        
0
-        def self.#{sym}
0
-          @@#{sym}
0
-        end
0
-
0
-        def #{sym}
0
-          @@#{sym}
0
-        end
0
+        unless defined? @@#{sym}  # unless defined? @@pagination_options
0
+          @@#{sym} = nil          #   @@pagination_options = nil
0
+        end                       # end
0
+                                  #
0
+        def self.#{sym}           # def self.pagination_options
0
+          @@#{sym}                #   @@pagination_options
0
+        end                       # end
0
+                                  #
0
+        def #{sym}                # def pagination_options
0
+          @@#{sym}                #   @@pagination_options
0
+        end                       # end
0
       EOS
0
     end
0
   end
0
@@ -34,19 +34,19 @@ class Module
0
     options = syms.extract_options!
0
     syms.each do |sym|
0
       class_eval(<<-EOS, __FILE__, __LINE__)
0
-        unless defined? @@#{sym}
0
-          @@#{sym} = nil
0
-        end
0
-        
0
-        def self.#{sym}=(obj)
0
-          @@#{sym} = obj
0
-        end
0
-        
0
-        #{"
0
-        def #{sym}=(obj)
0
-          @@#{sym} = obj
0
-        end
0
-        " unless options[:instance_writer] == false }
0
+        unless defined? @@#{sym}                       # unless defined? @@pagination_options
0
+          @@#{sym} = nil                               #   @@pagination_options = nil
0
+        end                                            # end
0
+                                                       #
0
+        def self.#{sym}=(obj)                          # def self.pagination_options=(obj)
0
+          @@#{sym} = obj                               #   @@pagination_options = obj
0
+        end                                            # end
0
+                                                       #
0
+        #{"                                            #
0
+        def #{sym}=(obj)                               # def pagination_options=(obj)
0
+          @@#{sym} = obj                               #   @@pagination_options = obj
0
+        end                                            # end
0
+        " unless options[:instance_writer] == false }  # # instance writer above is generated unless options[:instance_writer] == false
0
       EOS
0
     end
0
   end
...
112
113
114
115
116
117
 
 
 
118
119
120
...
112
113
114
 
 
 
115
116
117
118
119
120
0
@@ -112,9 +112,9 @@ class Module
0
 
0
     methods.each do |method|
0
       module_eval(<<-EOS, "(__DELEGATION__)", 1)
0
-        def #{prefix}#{method}(*args, &block)
0
-          #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)
0
-        end
0
+        def #{prefix}#{method}(*args, &block)                           # def customer_name(*args, &block)
0
+          #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)  #   client && client.__send__(:name, *args, &block)
0
+        end                                                             # end
0
       EOS
0
     end
0
   end
...
26
27
28
29
30
31
32
33
 
 
 
 
 
34
35
36
...
26
27
28
 
 
 
 
 
29
30
31
32
33
34
35
36
0
@@ -26,11 +26,11 @@ class Module
0
       end
0
 
0
       module_eval(<<-EOS, __FILE__, __LINE__)
0
-        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
0
-          #{with}.synchronize do
0
-            #{aliased_method}_without_synchronization#{punctuation}(*args, &block)
0
-          end
0
-        end
0
+        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)     # def expire_with_synchronization(*args, &block)
0
+          #{with}.synchronize do                                                    #   @@lock.synchronize do
0
+            #{aliased_method}_without_synchronization#{punctuation}(*args, &block)  #     expire_without_synchronization(*args, &block)
0
+          end                                                                       #   end
0
+        end                                                                         # end
0
       EOS
0
 
0
       alias_method_chain method, :synchronization
...
90
91
92
93
94
95
96
 
 
 
 
 
 
 
 
 
97
98
99
...
90
91
92
 
 
 
 
93
94
95
96
97
98
99
100
101
102
103
104
0
@@ -90,10 +90,15 @@ module ActiveSupport
0
         method_names.each do |method_name|
0
           alias_method_chain(method_name, :deprecation) do |target, punctuation|
0
             class_eval(<<-EOS, __FILE__, __LINE__)
0
-              def #{target}_with_deprecation#{punctuation}(*args, &block)
0
-                ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
0
-                #{target}_without_deprecation#{punctuation}(*args, &block)
0
-              end
0
+              def #{target}_with_deprecation#{punctuation}(*args, &block)   # def generate_secret_with_deprecation(*args, &block)
0
+                ::ActiveSupport::Deprecation.warn(                          #   ::ActiveSupport::Deprecation.warn(
0
+                  self.class.deprecated_method_warning(                     #     self.class.deprecated_method_warning(
0
+                    :#{method_name},                                        #       :generate_secret,
0
+                    #{options[method_name].inspect}),                       #       "You should use ActiveSupport::SecureRandom.hex(64)"),
0
+                  caller                                                    #     caller
0
+                )                                                           #   )
0
+                #{target}_without_deprecation#{punctuation}(*args, &block)  #   generate_secret_without_deprecation(*args, &block)
0
+              end                                                           # end
0
             EOS
0
           end
0
         end
...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
91
92
...
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
0
@@ -59,34 +59,36 @@ module ActiveSupport
0
         memoized_ivar = ActiveSupport::Memoizable.memoized_ivar_for(symbol)
0
 
0
         class_eval <<-EOS, __FILE__, __LINE__
0
-          include InstanceMethods
0
-
0
-          raise "Already memoized #{symbol}" if method_defined?(:#{original_method})
0
-          alias #{original_method} #{symbol}
0
-
0
-          if instance_method(:#{symbol}).arity == 0
0
-            def #{symbol}(reload = false)
0
-              if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty?
0
-                #{memoized_ivar} = [#{original_method}.freeze]
0
-              end
0
-              #{memoized_ivar}[0]
0
-            end
0
-          else
0
-            def #{symbol}(*args)
0
-              #{memoized_ivar} ||= {} unless frozen?
0
-              reload = args.pop if args.last == true || args.last == :reload
0
-
0
-              if defined?(#{memoized_ivar}) && #{memoized_ivar}
0
-                if !reload && #{memoized_ivar}.has_key?(args)
0
-                  #{memoized_ivar}[args]
0
-                elsif #{memoized_ivar}
0
-                  #{memoized_ivar}[args] = #{original_method}(*args).freeze
0
-                end
0
-              else
0
-                #{original_method}(*args)
0
-              end
0
-            end
0
-          end
0
+          include InstanceMethods                                                  # include InstanceMethods
0
+                                                                                   #
0
+          if method_defined?(:#{original_method})                                  # if method_defined?(:_unmemoized_mime_type)
0
+            raise "Already memoized #{symbol}"                                     #   raise "Already memoized mime_type"
0
+          end                                                                      # end
0
+          alias #{original_method} #{symbol}                                       # alias _unmemoized_mime_type mime_type
0
+                                                                                   #
0
+          if instance_method(:#{symbol}).arity == 0                                # if instance_method(:mime_type).arity == 0
0
+            def #{symbol}(reload = false)                                          #   def mime_type(reload = false)
0
+              if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty?  #     if reload || !defined?(@_memoized_mime_type) || @_memoized_mime_type.empty?
0
+                #{memoized_ivar} = [#{original_method}.freeze]                     #       @_memoized_mime_type = [_unmemoized_mime_type.freeze]
0
+              end                                                                  #     end
0
+              #{memoized_ivar}[0]                                                  #     @_memoized_mime_type[0]
0
+            end                                                                    #   end
0
+          else                                                                     # else
0
+            def #{symbol}(*args)                                                   #   def mime_type(*args)
0
+              #{memoized_ivar} ||= {} unless frozen?                               #     @_memoized_mime_type ||= {} unless frozen?
0
+              reload = args.pop if args.last == true || args.last == :reload       #     reload = args.pop if args.last == true || args.last == :reload
0
+                                                                                   #
0
+              if defined?(#{memoized_ivar}) && #{memoized_ivar}                    #     if defined?(@_memoized_mime_type) && @_memoized_mime_type
0
+                if !reload && #{memoized_ivar}.has_key?(args)                      #       if !reload && @_memoized_mime_type.has_key?(args)
0
+                  #{memoized_ivar}[args]                                           #         @_memoized_mime_type[args]
0
+                elsif #{memoized_ivar}                                             #       elsif @_memoized_mime_type
0
+                  #{memoized_ivar}[args] = #{original_method}(*args).freeze        #         @_memoized_mime_type[args] = _unmemoized_mime_type(*args).freeze
0
+                end                                                                #       end
0
+              else                                                                 #     else
0
+                #{original_method}(*args)                                          #       _unmemoized_mime_type(*args)
0
+              end                                                                  #     end
0
+            end                                                                    #   end
0
+          end                                                                      # end
0
         EOS
0
       end
0
     end
...
24
25
26
27
28
29
30
 
 
 
 
31
32
33
...
24
25
26
 
 
 
 
27
28
29
30
31
32
33
0
@@ -24,10 +24,10 @@ module ActiveSupport #:nodoc:
0
       # Lazy load the Unicode database so it's only loaded when it's actually used
0
       ATTRIBUTES.each do |attr_name|
0
         class_eval(<<-EOS, __FILE__, __LINE__)
0
-          def #{attr_name}
0
-            load
0
-            @#{attr_name}
0
-          end
0
+          def #{attr_name}  # def codepoints
0
+            load            #   load
0
+            @#{attr_name}   #   @codepoints
0
+          end               # end
0
         EOS
0
       end
0
 
...
234
235
236
237
238
239
 
 
 
240
241
242
...
234
235
236
 
 
 
237
238
239
240
241
242
0
@@ -234,9 +234,9 @@ module ActiveSupport
0
 
0
     %w(year mon month day mday wday yday hour min sec to_date).each do |method_name|
0
       class_eval <<-EOV
0
-        def #{method_name}
0
-          time.#{method_name}
0
-        end
0
+        def #{method_name}     # def year
0
+          time.#{method_name}  #   time.year
0
+        end                    # end
0
       EOV
0
     end
0
 

Comments

jherdman Sun Dec 28 16:42:40 -0800 2008

Beautiful. I like this.

anildigital Mon Dec 29 10:06:35 -0800 2008

nice

rsanheim Mon Dec 29 22:35:45 -0800 2008

Feels like this should be a language feature, or at least a post processing tool.

student Thu Jan 15 09:34:13 -0800 2009

There are a couple of places where there are comments above the code, rather than beside. The end result can appear to be code which has been disabled, rather than an explanation. In particular, I think that the annotation in activerecord/lib/active_record/base.rb needs to be annotated.

fxn Sat Feb 21 16:04:28 -0800 2009

Yes, we discussed the trade-offs in the IRC.

Those examples are there exceptionally because the lines would be really too wide. Check the section “Dinamically Generated Method” of the API conventions (http://wiki.github.com/lifo/docrails/rails-api-documentation-conventions)