"Richard Kilmer" <rich@infoether.com> schrieb im Newsbeitrag
news:BCEB7E82.B88A%rich@infoether.com...
>
>
>> This is not a continuation of the type thread other than trying to
>> continue
>> to discuss the ideas of adding metadata that could be used to help
the
>> runtime environment of Ruby. Before anyone says anything, I have
>> built lots
>> of Ruby code without this, and the runtime is just fine...think of
>> this as
>> exploration. Disregard all the other syntax I wrote on earlier...and
I
>> do
>> not care whether something is Hash-like, or is_a? Duck 
>>
>> class Person
>> attr_accessor :name
>> end
>>
>> def greet(person)
>> puts "Hello there #{person.<Person>name}"
>> end
>
> Isn't this effectively "to_name" or "as_name"?
>
I am not trying to coerce the object into another representation in
general
(although in the specific example its like that). Generally, I am
trying to
add to the message something more than the message symbol and
parameters...I
am trying to add the 'meaning' of the message as scoped in the namespace
of
the provided class/module.
Well, "meaning" is a difficult term with computers. "meaning" (or
semantic) for a coputer is always syntax. You just add some kind of
symbol to the method invocation which you could transport otherwise, i.e.
as method argument:
o = Object.new
def o.name(expect=nil)
case expect
when :Person
"Rich"
else
to_s
end
end
Alternatively you could do it a bit more behind the scenes via some Thread
local variable that is set somehow before the invocation:
class Object
alias :method_missing_old :method_missing
def method_missing(sym, *args, &b)
new_sym, ctx = sym.to_s.split(/_/, 2)
method_missing_old(sym, *args, &b) unless ctx
(Thread.current[:context] ||= ).push( ctx.to_sym )
begin
send(new_sym, *args, &b)
ensure
Thread.current[:context].pop
end
end
def called_as?(x)
c = Thread.current[:context]
c && c[-1] == x.to_sym
end
end
o = Object.new
def o.name
if called_as?(:Person)
"Rich"
else
to_s
end
end
p o.name
p o.name_Person
I am trying to add to the method additional
semantics of what I am asking from the target object. I am sending the
message 'name' with the meaning that 'name' has on a Person object.
That
receiver may or may not care...answering the way it wants, but right now
I
cannot express that semantics at all.
As I tried to demonstrate above, you can in fact express that already.
You merey add a new syntactic construct.
Regardless of all these issues, currently I don't see the real advantage
of this concept. Maybe you can explain a little more thouroughly why you
think it's better than method arguments or something else.
I guess I am not expressing myself with sufficient semantics 

Kind regards
robert
···
On 6/8/04 11:51 AM, "Dave Thomas" <dave@pragprog.com> wrote:
> On Jun 8, 2004, at 9:43, Richard Kilmer wrote: