[Wtr-general] Method Names as variables?

Keith Lancaster klancaster1957 at gmail.com
Tue Apr 18 16:16:45 EDT 2006


I am assuming Item(80) in your example is an object.

In Ruby, you can use the ³send² method to call a function.

Example:

class MyClass
    def my_function
        puts ³in my function²
    end
end

c = MyClass.new
function_name = ³my_function²
c.send(function_name)

HTH,
Keith



On 4/18/06 3:00 PM, "Rodrigo Julian Martin" <rodrigo.martin at enratio.com>
wrote:

> Hello!
>  
> I have another code questionŠ
>  
> Can I call an object method by using a variable?
>  
> I¹ve tried something like this:
>  
>  
> propertie=²className²
> a = Item(80).¹#{propertie}¹
>  
> And obviously doesn¹t workŠ
>  
> I¹ve also tried: 
>  
> a = Item(80).{propertie}
>  
> but this is a call to a hashŠ
>  
>  
> Any help would be really appreciatedŠ
> Thanks in Advance!
>  
>  
> Rodrigo Julian Martin
> 
> 
> _______________________________________________
> Wtr-general mailing list
> Wtr-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20060418/32ebc07e/attachment.html 


More information about the Wtr-general mailing list