From: nobu@... Date: 2017-09-25T21:39:59+00:00 Subject: [ruby-core:83009] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method Issue #13939 has been updated by nobu (Nobuyoshi Nakada). It's a bug in 2.4.0 and 2.4.1 only. Braces just after a literal has caused a syntax error before, like as: danielpclark (Daniel P. Clark) wrote: > 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) A brace block has higher precedence and is bound to the previous expression, and a literal cannot be a method call and have a block. shevegen (Robert A. Heiler) wrote: > I guess ruby core prefers short messages when possible (aka "syntax error, unexpected '}'") > but this is indeed not always extremely helpful. Unfortunately, this message is generated by bison, not us. ---------------------------------------- Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method https://bugs.ruby-lang.org/issues/13939#change-66920 * 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: