Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Ruby black magic? Meta Programming
My first exposure to Ruby was from Jim, and his "10 things every java
programmer should know about ruby" presentation.

Anyway, I probably shouldn't even be thinking about this kind of stuff
yet, but one thing in the presentation that I dug a lot was the use of
overriding Kernel#method_missing to queue messages and play them back
in order.

Anyway, I want to know what other kind of ,i guess I'll call it
metaprogramming, can be done in ruby.


For example, I remember reading something about Eiffel having the
ability to declare pre and post conditions for method calls on
objects, essentially bringing this criteria in as part of the
interface. Can something like this be done in Ruby? I'm assuming so,
but for some reason my google hits keep referring me to Pyhon's
Metaclass things, go figure.

Anyone got a link?

TIA
--
Thomas G. Willis
http://paperbackmusic.net



Report this thread to moderator Post Follow-up to this message
Old Post
Tom Willis
03-12-05 08:59 PM


Re: Ruby black magic? Meta Programming
On Sat, March 12, 2005 7:11 pm, Tom Willis said:
> My first exposure to Ruby was from Jim, and his "10 things every java
> programmer should know about ruby" presentation.
>
> Anyway, I probably shouldn't even be thinking about this kind of stuff
> yet, but one thing in the presentation that I dug a lot was the use of
> overriding Kernel#method_missing to queue messages and play them back
> in order.
>
> Anyway, I want to know what other kind of ,i guess I'll call it
> metaprogramming, can be done in ruby.
>
>
> For example, I remember reading something about Eiffel having the
> ability to declare pre and post conditions for method calls on
> objects, essentially bringing this criteria in as part of the
> interface. Can something like this be done in Ruby? I'm assuming so,
> but for some reason my google hits keep referring me to Pyhon's
> Metaclass things, go figure.
>
> Anyone got a link?

Currently pre/postconditions are proposed for Ruby 2.0, see\
http://www.rubygarden.org/ruby?Rite

You can achieve the same effect by creating a meta for something like
def_pre :methodname, def_post :methodname with associated blocks. Then
alias the actual :methodname, make the pre block respond to :methodname;
pre executes its block and then calls :methodname, after which post block
is called.

> Thomas G. Willis

E




Report this thread to moderator Post Follow-up to this message
Old Post
ES
03-12-05 08:59 PM


Re: Ruby black magic? Meta Programming
Excerpts from ES's mail of 12 Mar 2005 (EST):
> You can achieve the same effect by creating a meta for something like
> def_pre :methodname, def_post :methodname with associated blocks. Then
> alias the actual :methodname, make the pre block respond to
> :methodname; pre executes its block and then calls :methodname, after
> which post block is called.

See http://www.thekode.net/ruby/techniq...ingMethods.html for an
example implementation (which doesn't use alias).

But there are limitations to this technique that will only be resolved
in 2.0.

--
William <wmorgan-ruby-talk@masanjin.net>



Report this thread to moderator Post Follow-up to this message
Old Post
William Morgan
03-13-05 01:58 AM


Re: Ruby black magic? Meta Programming
Bruce Willis <tom.willis@gmail.com> asked:
> My first exposure to Ruby was from Jim, and his "10 things every java
> programmer should know about ruby" presentation.
>
> Anyway, I probably shouldn't even be thinking about this kind of stuff
> yet, but one thing in the presentation that I dug a lot was the use of
> overriding Kernel#method_missing to queue messages and play them back
> in order.
>
> Anyway, I want to know what other kind of ,i guess I'll call it
> metaprogramming, can be done in ruby.

I found this fun:
http://www.dave.burt.id.au/ruby/roman_numerals.rb

Cheers,
Dave



Report this thread to moderator Post Follow-up to this message
Old Post
Dave Burt
03-13-05 01:58 AM


Re: Ruby black magic? Meta Programming
On Sun, 13 Mar 2005, Tom Willis wrote:

> Anyway, I want to know what other kind of ,i guess I'll call it
> metaprogramming, can be done in ruby.

Here's a previously-unreleased edition of RubyX11:

http://artengine.ca/matju/RubyX11/R...0.6.pre1.tar.gz

Compared to the better-known version 0.5, this one replaces the
type-declaration interpreter, by a type-declaration _compiler_. The output
of the compiler is eval'ed at load time.

This is an unfinished project. I wrote the compiler in Oct.2001.

Because RubyX11 makes a clean separation between interface descriptions
and the actual task of encoding/decoding, this "client library" could also
be useful in writing a X11 _server_ in Ruby, as well as other things.

> For example, I remember reading something about Eiffel having the
> ability to declare pre and post conditions for method calls on
> objects, essentially bringing this criteria in as part of the
> interface. Can something like this be done in Ruby?

Ruby's backtracking method-lookup allows a nice kludge for imitating
pre/post conditions, as can be seen in MetaRuby (_my_ MetaRuby project,
not the other one). Also, Andrew Hunt had something much closer to
Eiffel's way, but using a preprocessor (?). And also a more generic
solution is AspectR, which implements LISP-style method-combinations
(:before/:after/:around/etc) and possibly a few other things (i don't
recall which).

 ________________________________________
_____________________________
Mathieu Bouchard -=- Montréal QC Canada -=- http://artengine.ca/matju





Report this thread to moderator Post Follow-up to this message
Old Post
Mathieu Bouchard
03-14-05 01:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Ruby archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:30 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.