Project

General

Profile

Actions

Bug #17559

closed

Conflict with BasicSocket#send and Object#send

Added by sergioro (Sergio Romero) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
[ruby-core:102155]

Description

Object#send can be used in most objects like:

's'.send :class
=> String

But BasicSocket objects call BasicSocket#send instead of Object#send:

TCPSocket('example.com', 'echo').send :class
Traceback (most recent call last):
	22: from /home/sergioro/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `<main>'
	21: from /home/sergioro/.rvm/gems/ruby-2.7.0/bin/ruby_executable_hooks:24:in `eval'
	20: from /home/sergioro/.rvm/gems/ruby-2.7.0/bin/irb:23:in `<main>'
	19: from /home/sergioro/.rvm/gems/ruby-2.7.0/bin/irb:23:in `load'
	18: from /home/sergioro/.rvm/gems/ruby-2.7.0/gems/irb-1.3.1/exe/irb:11:in `<top (required)>'
	 1: from (irb):5:in `<main>'
(irb):5:in `send': wrong number of arguments (given 1, expected 2..3) (ArgumentError)

How to call Object#send from a BasicSocket object?

Expected result:

TCPSocket('example.com', 'echo').send :class
=> TCPSocket

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Description updated (diff)
  • Status changed from Open to Closed

Object#__send__

Updated by matz (Yukihiro Matsumoto) almost 4 years ago

It's intentional. It's kind of a crash of cultures (message send from Lisp culture, data send from UNIX culture). The conflict has been known for years (actually from the beginning). That's the reason we introduced __send__ as workaround.

In addition, we are thinking of introducing method sending operator in the future. We have not decided which combination of characters should be used as an operator.

Matz.

Actions

Also available in: Atom PDF

Like0
Like0Like0