Equiv. ruby's method_missing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Equiv. ruby's method_missing

Bakki Kudva
Hi all,

Rail's Activerecord uses Ruby's method_missing to implement dynamic
finders such as find_by_#column_name()

which is done by defining in the receiver...
def method_missing(method_id, *arguments)
     if match = /find_(all_by|by)_([_a-zA-Z]\w*)/.match(method_id.to_s)
        finder, deprecated_finder = determine_finder(match),

determine_deprecated_finder(match)
       attribute_names = extract_attribute_names_from_match(match)
       super unless all_attributes_exists?(attribute_names)
<snip>

Does Smalltalk have some way of emulating this?
I am reading Smalltalk-80 books and don't see anything there. Is the
current language support such callback hooks (and others which trap
object create events and such?)

I was inspired to study this when I read an old thread (2005) on the
seaside list about writing an activerecord like layer for
Seaside...although GLORP may be a better option in the long run. This
is pretty much an academic excercise for me now.

THanks for your help,

bakki
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Equiv. ruby's method_missing

Ralph Johnson
> Does Smalltalk have some way of emulating this?

It is called doesNotUnderstand:

You can browse the image to see how it is used.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners