Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Calling a procedure with dinamyc name

Reply
Thread Tools

Calling a procedure with dinamyc name

 
 
Marcelo Paniagua
Guest
Posts: n/a
 
      06-04-2005
Hi there!

I'm using Kirbybase database and it has the peculiar way to access
fields data though methods. Is it posible to call such methods
passing the fieldname in a dinamic way?

instead of

client_id = table.client_id

I would like to use sometime like

field = 'client_id'
client_id = table.field or something like that.

This is also applicable to a program that I'm developing, in which I
want to find if a class has a given method... for example, I want to
find if a class Card has an "onplay" method.

Thanks

--
Este correo esta libre de virus!



 
Reply With Quote
 
 
 
 
Francis Hwang
Guest
Posts: n/a
 
      06-04-2005

On Jun 4, 2005, at 1:52 PM, Marcelo Paniagua wrote:

> Hi there!
>
> I'm using Kirbybase database and it has the peculiar way to access
> fields data though methods. Is it posible to call such methods
> passing the fieldname in a dinamic way?
>
> instead of
>
> client_id = table.client_id
>
> I would like to use sometime like
>
> field = 'client_id'
> client_id = table.field or something like that.
>
> This is also applicable to a program that I'm developing, in which I
> want to find if a class has a given method... for example, I want to
> find if a class Card has an "onplay" method.
> Thanks
>


Maybe you want this:

field = 'client_id'
client_id = table.send field

or maybe you want this

method = table.method :client_id
client_id = method.call

... you've got quite a few options.



> --
> Este correo esta libre de virus!
>
>
>


Francis Hwang
http://fhwang.net/



 
Reply With Quote
 
 
 
 
Marcelo Paniagua
Guest
Posts: n/a
 
      06-04-2005
For the the Kirbybase it seems like the right option. As for the other
example I have my doubts. What I want to do in that
case is something like this: I have an object of class Card. I want to
look though the object methods and find out if it has
an "onPlay" method, "onLefPlay" method, and so on. I want to do this
in order to let the user knows that he can use those
methods in a given time... Which option do you think is the right option?

Marcelo



Francis Hwang escribió:

>
> On Jun 4, 2005, at 1:52 PM, Marcelo Paniagua wrote:
>
>> Hi there!
>>
>> I'm using Kirbybase database and it has the peculiar way to access
>> fields data though methods. Is it posible to call such methods
>> passing the fieldname in a dinamic way?
>>
>> instead of
>>
>> client_id = table.client_id
>>
>> I would like to use sometime like
>>
>> field = 'client_id'
>> client_id = table.field or something like that.
>>
>> This is also applicable to a program that I'm developing, in which
>> I want to find if a class has a given method... for example, I want to
>> find if a class Card has an "onplay" method.
>> Thanks
>>

>
> Maybe you want this:
>
> field = 'client_id'
> client_id = table.send field
>
> or maybe you want this
>
> method = table.method :client_id
> client_id = method.call
>
> ... you've got quite a few options.
>
>
>
>> --
>> Este correo esta libre de virus!
>>
>>
>>

>
> Francis Hwang
> http://fhwang.net/
>
>
>


--
Este correo esta libre de virus!



 
Reply With Quote
 
Ryan Leavengood
Guest
Posts: n/a
 
      06-04-2005
Marcelo Paniagua wrote:
> Hi there!
>
> I'm using Kirbybase database and it has the peculiar way to access
> fields data though methods. Is it posible to call such methods
> passing the fieldname in a dinamic way?
>
> instead of
>
> client_id = table.client_id
>
> I would like to use sometime like
>
> field = 'client_id'
> client_id = table.field or something like that.


There are at least two basic options:

1. Call Object#send:

field = 'client_id'
client_id = table.send(field)

2. Use Object#method to get a method, then call it:

field = 'client_id'
method = table.method(field)
method.call

> This is also applicable to a program that I'm developing, in which I
> want to find if a class has a given method... for example, I want to
> find if a class Card has an "onplay" method.
> Thanks


You can ask an instance of Card if it responds to that method:

card = Card.new
if card.respond_to?('onplay')
# Do something
end

You may also want to research the method 'method_missing' which allows
for a lot of interesting tricks.

Regards,
Ryan


 
Reply With Quote
 
Francis Hwang
Guest
Posts: n/a
 
      06-04-2005
You could look at either Object#methods or Object#respond_to? depending=20=

on how you want to do it.

On Jun 4, 2005, at 2:05 PM, Marcelo Paniagua wrote:

> For the the Kirbybase it seems like the right option. As for the=20
> other example I have my doubts. What I want to do in that
> case is something like this: I have an object of class Card. I want=20=


> to look though the object methods and find out if it has
> an "onPlay" method, "onLefPlay" method, and so on. I want to do this=20=


> in order to let the user knows that he can use those
> methods in a given time... Which option do you think is the right=20
> option?
>
> Marcelo
>
>
>
> Francis Hwang escribi=F3:
>
>>
>> On Jun 4, 2005, at 1:52 PM, Marcelo Paniagua wrote:
>>
>>> Hi there!
>>>
>>> I'm using Kirbybase database and it has the peculiar way to access=20=


>>> fields data though methods. Is it posible to call such methods
>>> passing the fieldname in a dinamic way?
>>>
>>> instead of
>>>
>>> client_id =3D table.client_id
>>>
>>> I would like to use sometime like
>>>
>>> field =3D 'client_id'
>>> client_id =3D table.field or something like that.
>>>
>>> This is also applicable to a program that I'm developing, in which=20=


>>> I want to find if a class has a given method... for example, I want=20=


>>> to
>>> find if a class Card has an "onplay" method.
>>> Thanks
>>>

>>
>> Maybe you want this:
>>
>> field =3D 'client_id'
>> client_id =3D table.send field
>>
>> or maybe you want this
>>
>> method =3D table.method :client_id
>> client_id =3D method.call
>>
>> ... you've got quite a few options.
>>
>>
>>
>>> --=20
>>> Este correo esta libre de virus!
>>>
>>>
>>>

>>
>> Francis Hwang
>> http://fhwang.net/
>>
>>
>>

>
> --=20
> Este correo esta libre de virus!
>
>
>


Francis Hwang
http://fhwang.net/



 
Reply With Quote
 
Marcelo Paniagua
Guest
Posts: n/a
 
      06-04-2005
Thanks! I think that for Kirbybase I will get the method using the
fieldname and for the other case I will use the Object#respond_to?.

Marcelo Paniagua

Ryan Leavengood escribió:

> Marcelo Paniagua wrote:
>
>> Hi there!
>>
>> I'm using Kirbybase database and it has the peculiar way to access
>> fields data though methods. Is it posible to call such methods
>> passing the fieldname in a dinamic way?
>>
>> instead of
>>
>> client_id = table.client_id
>>
>> I would like to use sometime like
>>
>> field = 'client_id'
>> client_id = table.field or something like that.

>
>
> There are at least two basic options:
>
> 1. Call Object#send:
>
> field = 'client_id'
> client_id = table.send(field)
>
> 2. Use Object#method to get a method, then call it:
>
> field = 'client_id'
> method = table.method(field)
> method.call
>
>> This is also applicable to a program that I'm developing, in which
>> I want to find if a class has a given method... for example, I want to
>> find if a class Card has an "onplay" method.
>> Thanks

>
>
> You can ask an instance of Card if it responds to that method:
>
> card = Card.new
> if card.respond_to?('onplay')
> # Do something
> end
>
> You may also want to research the method 'method_missing' which allows
> for a lot of interesting tricks.
>
> Regards,
> Ryan
>
>


--
Este correo esta libre de virus!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
procedure as argument in procedure AlexWare VHDL 2 10-23-2009 09:14 AM
'Procedure or function <stored procedure name> has too many arguments specified',,,ARGH! Mike P ASP .Net 0 06-19-2006 01:19 PM
Dinamyc and static nat whit only one public ip address? mckennan Cisco 2 08-28-2005 03:28 PM
calling stored procedure from Visual FoxPro database JN ASP .Net 0 11-05-2003 03:00 PM
Calling a procedure Jon Cosby ASP .Net 1 08-11-2003 04:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57