From: 6ftdan@... Date: 2017-09-25T21:19:27+00:00 Subject: [ruby-core:83008] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method Issue #13939 has been updated by danielpclark (Daniel P. Clark). > Perhaps the error message could be more indicative of the error or what the exact problem is or how to solve it. I understand that the () provide additional information that is in some way useful to the parser, or whatever is responsible, so perhaps the message above could be changed somewhat. > I guess ruby core prefers short messages when possible (aka "syntax error, unexpected '}'") but this is indeed not always extremely helpful. With more recent changes such as the did-you-mean-gem, but also some other discussions about better and more fine-tuned control over warnings/error messages, that may be more helpful to the average ruby hacker. I apologize I wrote that earlier with a different error message. Here's what importing 'read_source' does in Ruby 2.4.2 (but will work for any other version of Ruby). ~~~ /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- read_source (LoadError) from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /home/danielpclark/dev/faster_path/test/monkeypatches/faster_path_test.rb:3:in `' from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/share/rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:15:in `block in
' from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `select' from /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/lib/rake/rake_test_loader.rb:4:in `
' rake aborted! Command failed with status (1) /home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/exe/rake:27:in `' /home/danielpclark/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `eval' /home/danielpclark/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `
' ~~~ I wasn't going to include it here because I think that problem should be a different bug report. The same error will occur for gem 'method_source' and only for Ruby 2.4.2. I'm not sure this require issue is a Ruby bug yet. The error shown in this report is not from being required but from running the test suite in the gem. > By the way your last example does not work as-is :D Ah, for that last example there should be a method defined within a class. ~~~ruby class Example def apple "Johny Apple Seed was here" end define_method :johny, instance_method(:apple) end ~~~ ---------------------------------------- Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method https://bugs.ruby-lang.org/issues/13939#change-66917 * Author: danielpclark (Daniel P. Clark) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- In Ruby 2.3 & 2.4.0 you can do this ~~~ruby define_method :some_method_name { "asdf" } ~~~ As of my trying 2.4.2 this is no longer supported. Anyone who tries to load my 'read_source' gem will get a failure message in require without explaining the specific area of code. ~~~ SyntaxError: /home/danielpclark/dev/read_source/test/support/example.rb:18: syntax error, unexpected '{', expecting keyword_end ethod :also_attr_method_name { "asdf" } ^ /home/danielpclark/dev/read_source/test/support/example.rb:18: syntax error, unexpected '}', expecting keyword_end so_attr_method_name { "asdf" } ^ from (irb):2:in `require_relative' from (irb):2 from /usr/share/rvm/rubies/ruby-2.4.2/bin/irb:11:in `
' ~~~ To fix my gem for Ruby 2.4.2 I now have to wrap the method name in parenthesis `()` ~~~ruby define_method(:some_method_name) { "asdf" } ~~~ And that will work. But I find this odd as the following will still work in 2.4.2: ~~~ruby define_method :johny, instance_method(:apple) ~~~ Which is still Seattle.rb style. -- https://bugs.ruby-lang.org/ Unsubscribe: