diff options
author | Xavier Noria <fxn@hashref.com> | 2010-04-03 10:56:15 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-03 10:56:15 -0700 |
commit | 11161e6c96fb6686a33e05ead106b96089ff9790 (patch) | |
tree | 35d5618f1a866ce8ba11efd8e6851d2fd7bbf5fc /activerecord | |
parent | 4996d1a445acd965d0064500ad00d692a742f669 (diff) | |
parent | 467d251c3dcbd3e4dd1e785a21d63535b795a64c (diff) | |
download | rails-11161e6c96fb6686a33e05ead106b96089ff9790.tar.gz rails-11161e6c96fb6686a33e05ead106b96089ff9790.tar.bz2 rails-11161e6c96fb6686a33e05ead106b96089ff9790.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 10 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 73 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/through_association_scope.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 133 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 21 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 20 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 25 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 15 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 16 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 6 |
12 files changed, 163 insertions, 175 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e379f4f967..e0625c3dbb 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,15 @@ *Rails 3.0.0 [Beta 2] (pending)* +* Add Relation extensions. [Pratik Naik] + + users = User.where(:admin => true).extending(User::AdminPowers) + + latest_users = User.order('created_at DESC') do + def posts_count + Post.count(:user_id => to_a.map(&:id)) + end + end + * To prefix the table names of all models in a module, define self.table_name_prefix on the module. #4032 [Andrew White] * Silenced "SHOW FIELDS" and "SET SQL_AUTO_IS_NULL=0" statements from the MySQL driver to improve log signal to noise ration in development [DHH] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7406daf837..20a8754b7c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1495,14 +1495,6 @@ module ActiveRecord # finder conditions. def configure_dependency_for_has_many(reflection, extra_conditions = nil) if reflection.options.include?(:dependent) - # Add polymorphic type if the :as option is present - dependent_conditions = [] - dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" - dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] - dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.table_name) if reflection.options[:conditions] - dependent_conditions << extra_conditions if extra_conditions - dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") - dependent_conditions = dependent_conditions.gsub('@', '\@') case reflection.options[:dependent] when :destroy method_name = "has_many_dependent_destroy_for_#{reflection.name}".to_sym @@ -1511,51 +1503,30 @@ module ActiveRecord end before_destroy method_name when :delete_all - # before_destroy do |record| - # self.class.send(:delete_all_has_many_dependencies, - # record, - # "posts", - # Post, - # %@...@) # this is a string literal like %(...) - # end - # end - module_eval <<-CALLBACK - before_destroy do |record| - self.class.send(:delete_all_has_many_dependencies, - record, - "#{reflection.name}", - #{reflection.class_name}, - %@#{dependent_conditions}@) - end - CALLBACK + before_destroy do |record| + self.class.send(:delete_all_has_many_dependencies, + record, + reflection.name, + reflection.klass, + reflection.dependent_conditions(record, self.class, extra_conditions)) + end when :nullify - # before_destroy do |record| - # self.class.send(:nullify_has_many_dependencies, - # record, - # "posts", - # Post, - # "user_id", - # %@...@) # this is a string literal like %(...) - # end - # end - module_eval <<-CALLBACK - before_destroy do |record| - self.class.send(:nullify_has_many_dependencies, - record, - "#{reflection.name}", - #{reflection.class_name}, - "#{reflection.primary_key_name}", - %@#{dependent_conditions}@) - end - CALLBACK - when :restrict - method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym - define_method(method_name) do - unless send(reflection.name).empty? - raise DeleteRestrictionError.new(reflection) - end + before_destroy do |record| + self.class.send(:nullify_has_many_dependencies, + record, + reflection.name, + reflection.klass, + reflection.primary_key_name, + reflection.dependent_conditions(record, self.class, extra_conditions)) + end + when :restrict + method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym + define_method(method_name) do + unless send(reflection.name).empty? + raise DeleteRestrictionError.new(reflection) end - before_destroy method_name + end + before_destroy method_name else raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, :nullify or :restrict (#{reflection.options[:dependent].inspect})" end diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index 6f0f698f1e..1d2f323112 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -135,7 +135,7 @@ module ActiveRecord def build_through_conditions conditions = @reflection.through_reflection.options[:conditions] if conditions.is_a?(Hash) - interpolate_sql(sanitize_sql(conditions)).gsub( + interpolate_sql(@reflection.through_reflection.klass.send(:sanitize_sql, conditions)).gsub( @reflection.quoted_table_name, @reflection.through_reflection.quoted_table_name) elsif conditions diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 9abf979cd0..632322b517 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -8,16 +8,15 @@ module ActiveRecord extend ActiveSupport::Concern module ClassMethods - # Returns a relation if invoked without any arguments. + # Returns an anonymous scope. # # posts = Post.scoped # posts.size # Fires "select count(*) from posts" and returns the count # posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects # - # Returns an anonymous named scope if any options are supplied. - # - # shirts = Shirt.scoped(:conditions => {:color => 'red'}) - # shirts = shirts.scoped(:include => :washing_instructions) + # fruits = Fruit.scoped + # fruits = fruits.where(:colour => 'red') if options[:red_only] + # fruits = fruits.limit(10) if limited? # # Anonymous \scopes tend to be useful when procedurally generating complex queries, where passing # intermediate values (scopes) around as first-class objects is convenient. @@ -25,7 +24,8 @@ module ActiveRecord # You can define a scope that applies to all finders using ActiveRecord::Base.default_scope. def scoped(options = {}, &block) if options.present? - Scope.init(self, options, &block) + relation = scoped.apply_finder_options(options) + block_given? ? relation.extending(Module.new(&block)) : relation else current_scoped_methods ? unscoped.merge(current_scoped_methods) : unscoped.clone end @@ -36,21 +36,21 @@ module ActiveRecord end # Adds a class method for retrieving and querying objects. A scope represents a narrowing of a database query, - # such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>. + # such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>. # # class Shirt < ActiveRecord::Base - # scope :red, :conditions => {:color => 'red'} - # scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true] + # scope :red, where(:color => 'red') + # scope :dry_clean_only, joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) # end # # The above calls to <tt>scope</tt> define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red, - # in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>. + # in effect, represents the query <tt>Shirt.where(:color => 'red')</tt>. # # Unlike <tt>Shirt.find(...)</tt>, however, the object returned by Shirt.red is not an Array; it resembles the association object - # constructed by a <tt>has_many</tt> declaration. For instance, you can invoke <tt>Shirt.red.find(:first)</tt>, <tt>Shirt.red.count</tt>, - # <tt>Shirt.red.find(:all, :conditions => {:size => 'small'})</tt>. Also, just - # as with the association objects, named \scopes act like an Array, implementing Enumerable; <tt>Shirt.red.each(&block)</tt>, - # <tt>Shirt.red.first</tt>, and <tt>Shirt.red.inject(memo, &block)</tt> all behave as if Shirt.red really was an Array. + # constructed by a <tt>has_many</tt> declaration. For instance, you can invoke <tt>Shirt.red.first</tt>, <tt>Shirt.red.count</tt>, + # <tt>Shirt.red.where(:size => 'small')</tt>. Also, just as with the association objects, named \scopes act like an Array, + # implementing Enumerable; <tt>Shirt.red.each(&block)</tt>, <tt>Shirt.red.first</tt>, and <tt>Shirt.red.inject(memo, &block)</tt> + # all behave as if Shirt.red really was an Array. # # These named \scopes are composable. For instance, <tt>Shirt.red.dry_clean_only</tt> will produce all shirts that are both red and dry clean only. # Nested finds and calculations also work with these compositions: <tt>Shirt.red.dry_clean_only.count</tt> returns the number of garments @@ -69,9 +69,7 @@ module ActiveRecord # Named \scopes can also be procedural: # # class Shirt < ActiveRecord::Base - # scope :colored, lambda { |color| - # { :conditions => { :color => color } } - # } + # scope :colored, lambda {|color| where(:color => color) } # end # # In this example, <tt>Shirt.colored('puce')</tt> finds all puce shirts. @@ -79,26 +77,13 @@ module ActiveRecord # Named \scopes can also have extensions, just as with <tt>has_many</tt> declarations: # # class Shirt < ActiveRecord::Base - # scope :red, :conditions => {:color => 'red'} do + # scope :red, where(:color => 'red') do # def dom_id # 'red_shirts' # end # end # end - # - # - # For testing complex named \scopes, you can examine the scoping options using the - # <tt>proxy_options</tt> method on the proxy itself. - # - # class Shirt < ActiveRecord::Base - # scope :colored, lambda { |color| - # { :conditions => { :color => color } } - # } - # end - # - # expected_options = { :conditions => { :colored => 'red' } } - # assert_equal expected_options, Shirt.colored('red').proxy_options - def scope(name, options = {}, &block) + def scope(name, scope_options = {}, &block) name = name.to_sym if !scopes[name] && respond_to?(name, true) @@ -106,17 +91,17 @@ module ActiveRecord "Overwriting existing method #{self.name}.#{name}." end - scopes[name] = lambda do |parent_scope, *args| - Scope.init(parent_scope, case options - when Hash, Relation - options - when Proc - options.call(*args) - end, &block) + scopes[name] = lambda do |*args| + options = scope_options.is_a?(Proc) ? scope_options.call(*args) : scope_options + + relation = scoped + relation = options.is_a?(Hash) ? relation.apply_finder_options(options) : scoped.merge(options) if options + block_given? ? relation.extending(Module.new(&block)) : relation end + singleton_class.instance_eval do define_method name do |*args| - scopes[name].call(self, *args) + scopes[name].call(*args) end end end @@ -127,73 +112,5 @@ module ActiveRecord end end - class Scope < Relation - attr_accessor :current_scoped_methods_when_defined - - delegate :scopes, :with_scope, :with_exclusive_scope, :scoped_methods, :scoped, :to => :klass - - def self.init(klass, options, &block) - relation = new(klass, klass.arel_table) - - scope = if options.is_a?(Hash) - klass.scoped.apply_finder_options(options.except(:extend)) - else - options ? klass.scoped.merge(options) : klass.scoped - end - - relation = relation.merge(scope) - - Array.wrap(options[:extend]).each {|extension| relation.send(:extend, extension) } if options.is_a?(Hash) - relation.send(:extend, Module.new(&block)) if block_given? - - relation.current_scoped_methods_when_defined = klass.send(:current_scoped_methods) - relation - end - - def first(*args) - if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) - to_a.first(*args) - else - args.first.present? ? apply_finder_options(args.first).first : super - end - end - - def last(*args) - if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) - to_a.last(*args) - else - args.first.present? ? apply_finder_options(args.first).last : super - end - end - - def ==(other) - case other - when Scope - to_sql == other.to_sql - when Relation - other == self - when Array - to_a == other.to_a - end - end - - private - - def method_missing(method, *args, &block) - if klass.respond_to?(method) - with_scope(self) do - if current_scoped_methods_when_defined && !scoped_methods.include?(current_scoped_methods_when_defined) && !scopes.include?(method) - with_scope(current_scoped_methods_when_defined) { klass.send(method, *args, &block) } - else - klass.send(method, *args, &block) - end - end - else - super - end - end - - end - end end diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 5e8fc104cb..0e48e229b3 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -277,6 +277,17 @@ module ActiveRecord !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) end + def dependent_conditions(record, base_class, extra_conditions) + dependent_conditions = [] + dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}" + dependent_conditions << "#{options[:as]}_type = '#{base_class.name}'" if options[:as] + dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions] + dependent_conditions << extra_conditions if extra_conditions + dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") + dependent_conditions = dependent_conditions.gsub('@', '\@') + dependent_conditions + end + private def derive_class_name class_name = name.to_s.camelize diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 8577ec58f7..4e62187449 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -13,8 +13,9 @@ module ActiveRecord delegate :insert, :to => :arel attr_reader :table, :klass + attr_accessor :extensions - def initialize(klass, table) + def initialize(klass, table, &block) @klass, @table = klass, table @implicit_readonly = nil @@ -22,6 +23,9 @@ module ActiveRecord SINGLE_VALUE_METHODS.each {|v| instance_variable_set(:"@#{v}_value", nil)} (ASSOCIATION_METHODS + MULTI_VALUE_METHODS).each {|v| instance_variable_set(:"@#{v}_values", [])} + @extensions = [] + + apply_modules(Module.new(&block)) if block_given? end def new(*args, &block) @@ -307,11 +311,26 @@ module ActiveRecord @should_eager_load ||= (@eager_load_values.any? || (@includes_values.any? && references_eager_loaded_tables?)) end + def ==(other) + case other + when Relation + other.to_sql == to_sql + when Array + to_a == other.to_a + end + end + + def inspect + to_a.inspect + end + protected def method_missing(method, *args, &block) if Array.method_defined?(method) to_a.send(method, *args, &block) + elsif @klass.scopes[method] + merge(@klass.send(method, *args, &block)) elsif @klass.respond_to?(method) @klass.send(:with_scope, self) { @klass.send(method, *args, &block) } elsif arel.respond_to?(method) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 37aaac0894..a26f1c0ac8 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -106,13 +106,29 @@ module ActiveRecord # A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the # same arguments to this method as you can to <tt>find(:first)</tt>. def first(*args) - args.any? ? apply_finder_options(args.first).first : find_first + if args.any? + if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) + to_a.first(*args) + else + apply_finder_options(args.first).first + end + else + find_first + end end # A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in all the # same arguments to this method as you can to <tt>find(:last)</tt>. def last(*args) - args.any? ? apply_finder_options(args.first).last : find_last + if args.any? + if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash)) + to_a.last(*args) + else + apply_finder_options(args.first).last + end + else + find_last + end end # A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 711df16bf1..d0efa2189d 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -20,10 +20,12 @@ module ActiveRecord table = Arel::Table.new(table_name, :engine => @engine) end - attribute = table[column] + unless attribute = table[column] + raise StatementInvalid, "No attribute named `#{column}` exists for table `#{table.name}`" + end case value - when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope + when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation values = value.to_a attribute.in(values) when Range diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index e224781016..b5e8b7570a 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -10,8 +10,9 @@ module ActiveRecord next if [:where, :having].include?(query_method) class_eval <<-CEVAL - def #{query_method}(*args) + def #{query_method}(*args, &block) new_relation = clone + new_relation.send(:apply_modules, Module.new(&block)) if block_given? value = Array.wrap(args.flatten).reject {|x| x.blank? } new_relation.#{query_method}_values += value if value.present? new_relation @@ -21,8 +22,9 @@ module ActiveRecord [:where, :having].each do |query_method| class_eval <<-CEVAL - def #{query_method}(*args) + def #{query_method}(*args, &block) new_relation = clone + new_relation.send(:apply_modules, Module.new(&block)) if block_given? value = build_where(*args) new_relation.#{query_method}_values += [*value] if value.present? new_relation @@ -34,8 +36,9 @@ module ActiveRecord attr_accessor :"#{query_method}_value" class_eval <<-CEVAL - def #{query_method}(value = true) + def #{query_method}(value = true, &block) new_relation = clone + new_relation.send(:apply_modules, Module.new(&block)) if block_given? new_relation.#{query_method}_value = value new_relation end @@ -43,8 +46,16 @@ module ActiveRecord end end - def lock(locks = true) + def extending(*modules) + new_relation = clone + new_relation.send :apply_modules, *modules + new_relation + end + + def lock(locks = true, &block) relation = clone + relation.send(:apply_modules, Module.new(&block)) if block_given? + case locks when String, TrueClass, NilClass clone.tap {|new_relation| new_relation.lock_value = locks || true } @@ -191,6 +202,12 @@ module ActiveRecord private + def apply_modules(modules) + values = Array.wrap(modules) + @extensions += values if values.present? + values.each {|extension| extend(extension) } + end + def reverse_sql_order(order_query) order_query.to_s.split(/,/).each { |s| if s.match(/\s(asc|ASC)$/) diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a17de1bdbb..8fdd64afcc 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -6,10 +6,9 @@ module ActiveRecord merged_relation = clone return merged_relation unless r - (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method| - unless (value = r.send(:"#{method}_values")).blank? - merged_relation.send(:"#{method}_values=", value) - end + (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method| + value = r.send(:"#{method}_values") + merged_relation.send(:"#{method}_values=", value) if value.present? end merged_relation = merged_relation.joins(r.joins_values) @@ -26,7 +25,7 @@ module ActiveRecord merged_relation.where_values = merged_wheres - ActiveRecord::Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method| + Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method| unless (value = r.send(:"#{method}_value")).nil? merged_relation.send(:"#{method}_value=", value) end @@ -34,6 +33,9 @@ module ActiveRecord merged_relation.lock_value = r.lock_value unless merged_relation.lock_value + # Apply scope extension modules + merged_relation.send :apply_modules, r.extensions + merged_relation end @@ -69,7 +71,7 @@ module ActiveRecord result end - VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, + VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend, :order, :select, :readonly, :group, :having, :from, :lock ] def apply_finder_options(options) @@ -84,6 +86,7 @@ module ActiveRecord relation = relation.where(options[:conditions]) if options.has_key?(:conditions) relation = relation.includes(options[:include]) if options.has_key?(:include) + relation = relation.extending(options[:extend]) if options.has_key?(:extend) relation end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 1e345399f5..7b9e680c02 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -572,4 +572,20 @@ class RelationTest < ActiveRecord::TestCase assert_equal Post.all, all_posts.all end + def test_anonymous_extension + relation = Post.where(:author_id => 1).order('id ASC') do + def author + 'lifo' + end + end + + assert_equal "lifo", relation.author + assert_equal "lifo", relation.limit(1).author + end + + def test_named_extension + relation = Post.where(:author_id => 1).order('id ASC').extending(Post::NamedExtension) + assert_equal "lifo", relation.author + assert_equal "lifo", relation.limit(1).author + end end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 704313649a..d092c4bf09 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -1,4 +1,10 @@ class Post < ActiveRecord::Base + module NamedExtension + def author + 'lifo' + end + end + scope :containing_the_letter_a, where("body LIKE '%a%'") scope :ranked_by_comments, order("comments_count DESC") scope :limit_by, lambda {|l| limit(l) } |