* [ruby-core:82999] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
@ 2017-09-25 15:43 ` 6ftdan
2017-09-25 18:15 ` [ruby-core:83004] " shevegen
` (4 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: 6ftdan @ 2017-09-25 15:43 UTC (permalink / raw
To: ruby-core
Issue #13939 has been reported by danielpclark (Daniel P. Clark).
----------------------------------------
Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
https://bugs.ruby-lang.org/issues/13939
* 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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83004] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
2017-09-25 15:43 ` [ruby-core:82999] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method 6ftdan
@ 2017-09-25 18:15 ` shevegen
2017-09-25 21:10 ` [ruby-core:83007] " asterite
` (3 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: shevegen @ 2017-09-25 18:15 UTC (permalink / raw
To: ruby-core
Issue #13939 has been updated by shevegen (Robert A. Heiler).
Let's ignore the "Seattle.rb style" for the moment because I don't know of such a
thing - may well be seattle-duck style. :P
But anyway, I agree with you in at the least one point, which is the warning message:
> Anyone who tries to load my 'read_source' gem will get a failure message
> in require without explaining the specific area of code.
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 helpul.
To the issue about differential parsing, that is actually indeed strange.
Even more surprising is that I actually thought that:
define_method(:some_method_name) { "asdf" }
Is the only way to use define_method() :D
I think I used that always ...
It reminds me a bit of:
get '/' do
play_intro_music
end
versus
get '/' { play_intro_music }
# which does not work
versus
get('/') { play_intro_music }
which works. I always thought that in some cases the ruby parse
needs the (). I'd love to be able to make them optional in the
second case. Oddly enough, for method DEFINITIONS, I always use
() when there are arguments, so "def foo(bar)" is what I prefer
over "def foo bar". This is more an aside though, it is strange
that this changed.
By the way your last example does not work as-is :D
define_method :johny, instance_method(:apple)
NoMethodError: undefined method `instance_method' for main:Object
Sorry for nitpicking there, I understand what you mean.
I guess it may be because of {} having different meanings in ruby
but then again, there was probably some reason unless it was an
accident. It's ~3:15 in Tokyo so I guess in a few hours perhaps
some from the ruby core team can chime in. I did not even know
that we could omit the () there, that was awesome if that was
possible. I remember in my code though, that whenever I used
define_method(), I always used () ... usually in combination with
some *eval* method thing.
----------------------------------------
Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
https://bugs.ruby-lang.org/issues/13939#change-66913
* 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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83007] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
2017-09-25 15:43 ` [ruby-core:82999] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method 6ftdan
2017-09-25 18:15 ` [ruby-core:83004] " shevegen
@ 2017-09-25 21:10 ` asterite
2017-09-25 21:19 ` [ruby-core:83008] " 6ftdan
` (2 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: asterite @ 2017-09-25 21:10 UTC (permalink / raw
To: ruby-core
Issue #13939 has been updated by asterite (Ary Borenszweig).
I think this was introduced in https://github.com/ruby/ruby/commit/9987109
Basically, any call `foo arg { }` when `arg` is a literal now gives an error.
I think this is a huge breaking change, for example if you had something like:
```
describe "foo" {
it "does something" {
}
}
```
Now it no longer works, though I don't know if someone writes code like that.
Maybe the error makes sense because `{` binds the thing to its left as a block, but I don't know :-)
----------------------------------------
Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
https://bugs.ruby-lang.org/issues/13939#change-66916
* 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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83008] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
` (2 preceding siblings ...)
2017-09-25 21:10 ` [ruby-core:83007] " asterite
@ 2017-09-25 21:19 ` 6ftdan
2017-09-25 21:39 ` [ruby-core:83009] " nobu
2017-11-10 8:01 ` [ruby-core:83726] [Ruby trunk Bug#13939][Rejected] " hsbt
5 siblings, 0 replies; 6+ messages in thread
From: 6ftdan @ 2017-09-25 21:19 UTC (permalink / raw
To: ruby-core
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 `<top (required)>'
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 <main>'
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 `<main>'
rake aborted!
Command failed with status (1)
/home/danielpclark/.rvm/gems/ruby-2.3.5/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/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 `<main>'
~~~
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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83009] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
` (3 preceding siblings ...)
2017-09-25 21:19 ` [ruby-core:83008] " 6ftdan
@ 2017-09-25 21:39 ` nobu
2017-11-10 8:01 ` [ruby-core:83726] [Ruby trunk Bug#13939][Rejected] " hsbt
5 siblings, 0 replies; 6+ messages in thread
From: nobu @ 2017-09-25 21:39 UTC (permalink / raw
To: ruby-core
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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83726] [Ruby trunk Bug#13939][Rejected] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
` (4 preceding siblings ...)
2017-09-25 21:39 ` [ruby-core:83009] " nobu
@ 2017-11-10 8:01 ` hsbt
5 siblings, 0 replies; 6+ messages in thread
From: hsbt @ 2017-11-10 8:01 UTC (permalink / raw
To: ruby-core
Issue #13939 has been updated by hsbt (Hiroshi SHIBATA).
Status changed from Open to Rejected
Assignee set to nobu (Nobuyoshi Nakada)
----------------------------------------
Bug #13939: Ruby 2.4.2 has issue supporting Seattle.rb style for define_method
https://bugs.ruby-lang.org/issues/13939#change-67762
* Author: danielpclark (Daniel P. Clark)
* Status: Rejected
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* 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 `<main>'
~~~
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/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-11-10 8:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-13939.20170925154339@ruby-lang.org>
2017-09-25 15:43 ` [ruby-core:82999] [Ruby trunk Bug#13939] Ruby 2.4.2 has issue supporting Seattle.rb style for define_method 6ftdan
2017-09-25 18:15 ` [ruby-core:83004] " shevegen
2017-09-25 21:10 ` [ruby-core:83007] " asterite
2017-09-25 21:19 ` [ruby-core:83008] " 6ftdan
2017-09-25 21:39 ` [ruby-core:83009] " nobu
2017-11-10 8:01 ` [ruby-core:83726] [Ruby trunk Bug#13939][Rejected] " hsbt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).