Skip to content

The & operator doesn't work with quoted symbols #5066

@pcarlisle

Description

@pcarlisle

Environment

jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a Java HotSpot(TM) 64-Bit Server VM 25.162-b12 on 1.8.0_162-b12 +jit [linux-x86_64]

Linux 4.14.14-1-ARCH #1 SMP PREEMPT Fri Jan 19 18:42:04 UTC 2018 x86_64 GNU/Linux

Expected Behavior

% ruby -v
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
% irb
irb(main):001:0> (1..3).reduce(&:'+')
=> 6
irb(main):002:0> (1..3).map(&:'to_s')
=> ["1", "2", "3"]
irb(main):003:0> 

Actual Behavior

irb(main):006:0> (1..3).reduce(&:+)
=> 6
irb(main):007:0> (1..3).reduce(&:'+')
NoMethodError: undefined method `+' for 1:Fixnum
	from org/jruby/RubyRange.java:495:in `each'
	from org/jruby/RubyEnumerable.java:931:in `inject'
	from (irb):7:in `<eval>'
	from org/jruby/RubyKernel.java:995:in `eval'
	from org/jruby/RubyKernel.java:1316:in `loop'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from /home/patrick/.rbenv/versions/jruby-9.1.16.0/bin/irb:13:in `<main>'
irb(main):008:0> method = :'+'
=> :+
irb(main):009:0> (1..3).reduce(&method)
=> 6

irb(main):012:0> (1..3).map(&:'to_s')
NoMethodError: undefined method `to_s' for 1:Fixnum
	from org/jruby/RubyRange.java:495:in `each'
	from org/jruby/RubyEnumerable.java:830:in `map'
	from (irb):12:in `<eval>'
	from org/jruby/RubyKernel.java:995:in `eval'
	from org/jruby/RubyKernel.java:1316:in `loop'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from /home/patrick/.rbenv/versions/jruby-9.1.16.0/bin/irb:13:in `<main>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions