Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

Help with simple meta programming


Hi,

This is a basic question of meta-programming with Ruby, which I'm
still getting familiar with.

I want to change/create a new attr_accessor such that it calls a kind
of proxy for retrieving the variable (which is not actually stored in
the object itself but rather on the database).

def variable
  invoke_method(variable)
  ...
end

def variable=(value)
  invoke_method(variable, value)
  ...
end

So, I catch the method name which should correspond to the variable
(except for the set method, which includes an extra '=') and pass it
to another function.

Any hints on how to get it done the right way? Thanks!

Cheers,

Mrio

On 5/30/07, mario.lo@gmail.com <mario.lo@gmail.com> wrote:

Maybe you would like to have a look at my personal favorite of all
Ruby Quizzes(*) (well that is of course save my own - just kidding-
there are lots of close seconds BTW):
http://rubyquiz.com/quiz67.html
I am quite sure that this should cover your needs.

Cheers
Robert

(*) although I miserably failed to find a solution (at that time).

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc