obj.send(symbol [, args…]) → obj
obj.send (symbol [, args…]) → obj
http://ruby-doc.org/core/classes/Object.html#M000999
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.
7stud
July 31, 2011, 8:01pm
2
On Jul 31, 2011, at 10:51 AM, 7stud – wrote:
end
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 W.
Twitter: http://www.twitter.com/cwgem
7stud
July 31, 2011, 8:47pm
3
Chris W. 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. So in your opinion is this wrong:
obj.send(symbol [, args…]) → args
or this:
obj.send(symbol [, args…]) → symbol
Or, are those merely misleading? Remember the context is computer
programming, not language phonetics.
7stud
July 31, 2011, 10:13pm
4
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:
7stud
July 31, 2011, 8:52pm
5
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 R. Bennett
Senior Software Consultant
Business: http://www.bbsinc.biz
Linked In: http://www.linkedin.com/in/keithrbennett
Blogs: http://krbtech.wordpress.com , http://keithrbennett.wordpress.com
7stud
August 1, 2011, 1:16am
6
On Jul 31, 2011, at 1:08 PM, Eric H. 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
Done:
Regards,
Chris W.
Twitter: http://www.twitter.com/cwgem
7stud
July 31, 2011, 10:22pm
7
On Sun, Jul 31, 2011 at 8:47 PM, 7stud – [email protected]
wrote:
Chris W. 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.
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