This project is archived and is in readonly mode.
[PATCH] Rails 3.0 console hard aborts on attempted autocompletion in Ruby 1.8.7, and prints inappropriate deprecation notice in Ruby 1.9.2
-
Andrew C. Greenberg
- Title changed from Rails 3.0 console hard aborts on attempted autocompletion [PATCH supplied] to [PATCH] Rails 3.0 console hard aborts on attempted autocompletion
-
Brian Candler
but instead of returning an array of Strings, as Class and its progeny do, Arel::Attribute::Predications.method_missing returns an array of Symbols
Unfortunately, this depends on which Ruby version you are using.
$ ruby -e 'p String.instance_methods[0,5]' ["%", "select", "[]=", "inspect", "<<"] $ ruby19 -e 'p String.instance_methods[0,5]' [:<=>, :==, :eql?, :hash, :casecmp]And an array of symbols does not like to be sorted, since symbols do not respond to "<=>". Boom!
Similarly:
$ ruby -e 'p [:foo, :bar].sort' -e:1:in `sort': undefined method `<=>' for :foo:Symbol (NoMethodError) from -e:1 $ ruby19 -e 'p [:foo, :bar].sort' [:bar, :foo]However, even in 1.9 you can't mix Symbol and String in a sort:
$ ruby19 -e 'p [:foo, "bar"].sort' -e:1:in `sort': comparison of Symbol with String failed (ArgumentError) from -e:1:in `<main>'So I think you should map PREDICATES to strings only if RUBY_VERSION < "1.9"
-
Andrew C. Greenberg
A useful observation, and it may explain how this wasn't caught earlier. Even so, the deprecation notice is still routinely printed in the rails console for expression autoompletion, and that should be fixed. Accordingly, I added a test to catch the ruby version dependence, added your suggested change, and included the previous changes to remove the version dependence.
In retrospect, it seems to me that using the array and override of #instance_methods is a brittle hack in the original. A better method might have been simply to metaprogam all the methods into the module (adding the dep warnings for the use of the procedure, not the introspection), and let the respective rubies determine how they would report the list of methods. Rather than do that, I leave it to the arel community to explain what functionality or purpose Predications still has, if any. If it is totally vestigial, perhaps the existing stuff is good enough.
Anyway, I attach a patch that repairs the repair so it works now with 1.8.7 and 1.9.2, AND eliminates the random deprecation messages in the ruby console hsving no relation to the autocompletion.
-
Andrew C. Greenberg
- Title changed from [PATCH] Rails 3.0 console hard aborts on attempted autocompletion to [PATCH] Rails 3.0 console hard aborts on attempted autocompletion in Ruby 1.8.7, and prints inappropriate deprecation notice in Ruby 1.9.2
-
Andrew C. Greenberg
- Tag set to arel console
-
Andrew C. Greenberg
- Tag changed from arel console to arel, console
-
Ryan Bigg
- Importance changed from to Low
Your patch does not apply to the
rails/arelrepository because the files it modifies are no longer there. Please update it to reflect this. -
Ryan Bigg
I cannot reproduce this on Rails master.
-
Stephen Davis
This issue is still present in Rails 3.0.1
$ rails -v Rails 3.0.1 $ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] $ rails new testapp ; cd testapp $ rails c Loading development environment (Rails 3.0.1) irb(main):001:0> Time.now.press tab to autocomplete here, and you get
this module is deprecated, please use the PREDICATES constant /usr/lib/ruby/1.8/irb/completion.rb:162:in `sort!': undefined method `<=>' for :not_in_all:Symbol (NoMethodError) from /usr/lib/ruby/1.8/irb/completion.rb:162 from /usr/lib/ruby/1.8/irb/input-method.rb:97:in `call' from /usr/lib/ruby/1.8/irb/input-method.rb:97:in `readline' from /usr/lib/ruby/1.8/irb/input-method.rb:97:in `gets' from /usr/lib/ruby/1.8/irb.rb:140 from /usr/lib/ruby/1.8/irb.rb:271:in `signal_status' from /usr/lib/ruby/1.8/irb.rb:139 from /usr/lib/ruby/1.8/irb/ruby-lex.rb:189:in `call' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:189:in `buf_input' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:104:in `getc' from /usr/lib/ruby/1.8/irb/slex.rb:206:in `match_io' from /usr/lib/ruby/1.8/irb/slex.rb:76:in `match' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:287:in `token' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:263:in `lex' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:234:in `each_top_level_statement' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch' from /usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement' from /usr/lib/ruby/1.8/irb.rb:154:in `eval_input' from /usr/lib/ruby/1.8/irb.rb:71:in `start' from /usr/lib/ruby/1.8/irb.rb:70:in `catch' from /usr/lib/ruby/1.8/irb.rb:70:in `start' from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start' from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start' from /usr/lib/ruby/gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:23 from script/rails:6:in `require' from script/rails:6
