Send() docs are wrong

obj.send(symbol [, args...]) → obj
obj.__send__(symbol [, args...]) → obj

Somehow, I don't expect the return value of send() to be the receiver.
Let's test send()'s return value using the example provided:

class Klass
     def hello(*args)
       "Hello " + args.join(' ')
     end
end

k = Klass.new
x = k.send :hello, "gentle", "readers"

puts x.class

--output:--
String

According to the docs, the return value of send() should be k, the
receiver, and k.class would therefore output: Klass.

···

--
Posted via http://www.ruby-forum.com/.

Potentially misleading yes, incorrect no. If you call send on an object you get an object back. It may be the same object, it may be another object. You could say

obj.send(symbol [, args...]) → otherobj

Which would work for your case, but not if the object itself was returned. Take for example:

class Klass
  def test
    self
  end
end

k = Klass.new
puts (k.send :test).class

--output:--
Klass

Regards,
Chris White
Twitter: http://www.twitter.com/cwgem

···

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

obj.send(symbol [, args...]) → obj
obj.__send__(symbol [, args...]) → obj

Somehow, I don't expect the return value of send() to be the receiver.
Let's test send()'s return value using the example provided:

class Klass
    def hello(*args)
      "Hello " + args.join(' ')
    end
end

k = Klass.new
x = k.send :hello, "gentle", "readers"

puts x.class

--output:--
String

According to the docs, the return value of send() should be k, the
receiver, and k.class would therefore output: Klass.

I agree… Please file a bug so I will know to fix it when I have time:

···

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

obj.send(symbol [, args...]) → obj
obj.__send__(symbol [, args...]) → obj

Somehow, I don't expect the return value of send() to be the receiver.

Chris White wrote in post #1014020:

···

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

end
receiver, and k.class would therefore output: Klass.

Potentially misleading yes, incorrect no.

Oh, please.

--
Posted via http://www.ruby-forum.com/\.

My two cents...I think something like this would be preferable:

obj1.send(symbol [, args...]) → obj2

...or even better...

obj.send(instance_method_name_as_symbol [, args...]) → instance_method_return_value

I agree that use of 'obj' for both is ambiguous, and think it's important for documentation to be more precise than that.

- Keith

···

---
Keith R. Bennett
Senior Software Consultant
Business: http://www.bbsinc.biz
Linked In: Keith Bennett - Bennett Business Solutions, Inc. | LinkedIn
Blogs: http://krbtech.wordpress.com, http://keithrbennett.wordpress.com

On Jul 31, 2011, at 2:00 PM, Chris White wrote:

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

obj.send(symbol [, args...]) → obj
obj.__send__(symbol [, args...]) → obj

Somehow, I don't expect the return value of send() to be the receiver.
Let's test send()'s return value using the example provided:

class Klass
   def hello(*args)
     "Hello " + args.join(' ')
   end
end

k = Klass.new
x = k.send :hello, "gentle", "readers"

puts x.class

--output:--
String

According to the docs, the return value of send() should be k, the
receiver, and k.class would therefore output: Klass.

Potentially misleading yes, incorrect no. If you call send on an object you get an object back. It may be the same object, it may be another object. You could say

obj.send(symbol [, args...]) → otherobj

Which would work for your case, but not if the object itself was returned. Take for example:

class Klass
  def test
    self
end
end

k = Klass.new
puts (k.send :test).class

--output:--
Klass

Regards,
Chris White
Twitter: http://www.twitter.com/cwgem

Done:

Regards,
Chris White
Twitter: http://www.twitter.com/cwgem

···

On Jul 31, 2011, at 1:08 PM, Eric Hodel wrote:

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

obj.send(symbol [, args...]) → obj
obj.__send__(symbol [, args...]) → obj

Somehow, I don't expect the return value of send() to be the receiver.

I agree… Please file a bug so I will know to fix it when I have time:

Ruby Issue Tracking System

I guess you are referring to
http://www.ruby-doc.org/core/classes/Object.html#M000999

It never occurred to me that obj and obj must be the same object,
especially since the example shows differently. I believe it is most
reasonable to expect to get back what the method returns. Were you
actually misled into believing that you always get back the original
receiver?

Kind regards

robert

···

On Sun, Jul 31, 2011 at 8:47 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:

Chris White wrote in post #1014020:

On Jul 31, 2011, at 10:51 AM, 7stud -- wrote:

end
receiver, and k.class would therefore output: Klass.

Potentially misleading yes, incorrect no.

Oh, please.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/