From 635f11d7fb8e7382314f5484d924b755a1e91be6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 28 Jul 2010 14:16:09 -0700 Subject: no need for a lambda --- lib/arel/algebra/attributes/attribute.rb | 4 ++-- lib/arel/algebra/relations/relation.rb | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index 50d79fa4b9..13781f47e0 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -29,6 +29,8 @@ module Arel @ancestor == other.ancestor end + alias :eql? :== + def named?(hypothetical_name) (@alias || name).to_s == hypothetical_name.to_s end @@ -41,8 +43,6 @@ module Arel row[self] end - alias :eql? :== - def hash @hash ||= name.hash + root.relation.hash end diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 9cb38218c0..62d9bf177c 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -187,9 +187,11 @@ module Arel end def position_of(attribute) - (@position_of ||= Hash.new do |h, attribute| - h[attribute] = attributes.index(self[attribute]) - end)[attribute] + @position_of ||= {} + + return @position_of[attribute] if @position_of.key? attribute + + @position_of[attribute] = attributes.index(attributes[attribute]) end private -- cgit v1.2.3