diff --git a/lib/ap/core_ext/array.rb b/lib/ap/core_ext/array.rb index 2c260d1..4013ad0 100644 --- a/lib/ap/core_ext/array.rb +++ b/lib/ap/core_ext/array.rb @@ -19,7 +19,7 @@ class Array #:nodoc: arr = self.__send__(:"original_#{operator.object_id}", *args) if self.instance_variable_defined?('@__awesome_methods__') arr.instance_variable_set('@__awesome_methods__', self.instance_variable_get('@__awesome_methods__')) - arr.sort! + arr.sort! { |a, b| a.to_s <=> b.to_s } # Need the block since Ruby 1.8.x can't sort arrays of symbols. end arr end diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb index 743892b..7ce206b 100644 --- a/spec/methods_spec.rb +++ b/spec/methods_spec.rb @@ -406,4 +406,23 @@ describe "Methods arrays" do out = Hello.methods.grep(/^m(\d)$/) { %w(none one)[$1.to_i] }.ai(:plain => true) out.should == "[\n [0] none() Hello\n [1] one() Hello\n]" end + + # See https://github.com/michaeldv/awesome_print/issues/30 for details. + it "grepping methods and converting them to_sym should work as expected" do + class Hello + private + def him; end + + def his + private_methods.grep(/^h..$/) { |n| n.to_sym } + end + + def her + private_methods.grep(/^.e.$/) { |n| n.to_sym } + end + end + + hello = Hello.new + (hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }.should == [ :him, :his ] + end end