I tried so hard to find an example of Ruby using smalltalk message syntax.
You can do something like:

class Dictionary
    attr_accessor :dict
    
    def initialize()
        @dict = {}
    end
    
    def at(*args)        
        if (args.length == 1) then
            return @dict[args[0]]
        end
        @dict[args[0]] = args[1][:put]
    end    
end

dict = Dictionary.new
dict.at 3, put: 4
puts dict.dict
puts dict.at 3


But it's pretty expensive to disambiguate messages to "at" this way.

The JS approach was much simpler since each message like 'at:put:' or 'at'
were sent to appropriate receiver functions, whereas this is just a
spaghetti :\

I'm sure there's more elegant way of doing this in Ruby but I haven't found
it :|



--
View this message in context: 
http://forum.world.st/How-do-Smalltalk-disambiguate-messages-tp4918946p4918959.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to