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!
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/
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.
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
Francis Hwang
http://fhwang.net/
Marcelo Paniagua
Ryan Leavengood escribió:
--