Hi there, after I searched the ruby-doc.org site I couldn't find a hint
how to call a class method on different classes.
I've a helper class which parses a text input and which should either call
Role.something or
Organisation.anotherthing
depening which parameter was passed.
Please give a little hint to proceed. Thanks a lot...
···
--
Daniel Völkerts
Protected by Anti Pesto. -- Wallace & Gromit
Just do it
if condition
Role.something
else
Organisation.anotherthing
end
Nothing special.
···
On Tue, Oct 03, 2006 at 11:05:43PM +0900, Daniel V?lkerts wrote:
Hi there, after I searched the ruby-doc.org site I couldn't find a hint
how to call a class method on different classes.
I've a helper class which parses a text input and which should either call
Role.something or
Organisation.anotherthing
depening which parameter was passed.
Please give a little hint to proceed. Thanks a lot...
Guest20
(Guest)
3
class Test
def self.test
puts "The huge test...OF DOOM!"
end
end
Test.test # => The huge test...OF DOOM!
Test.test isn't really a static method, but a singleton method on
Test. Then just do a test in your method:
def call_one_or_the_other(x)
case x
when SomeClass
Role.something
when OtherClass
Organisation.anotherthing
end
end
···
On 10/3/06, Daniel Völkerts <daniel@voelkerts.de> wrote:
Hi there, after I searched the ruby-doc.org site I couldn't find a hint
how to call a class method on different classes.
I've a helper class which parses a text input and which should either call
Role.something or
Organisation.anotherthing
depening which parameter was passed.
Please give a little hint to proceed. Thanks a lot...
--
Daniel Völkerts
Protected by Anti Pesto. -- Wallace & Gromit
--
- Simen
Okay, misleading question.
What if I like to call the classes dynamically e.g.
def mymethod(class,method)
call(class,method,options)
end
?
Where call is the Ruby function I'm looking for.
greetings,
···
--
Daniel Völkerts
Protected by Anti Pesto. -- Wallace & Gromit
Class.send(:method, *options) or
const_get('Class').send(:method, *options)
possibly
const_get('Class').send(:method, *options, &block) but i'm not sure
with this one.
···
On 10/3/06, Daniel Völkerts <daniel@voelkerts.de> wrote:
Okay, misleading question.
What if I like to call the classes dynamically e.g.
def mymethod(class,method)
call(class,method,options)
end
?
Where call is the Ruby function I'm looking for.
Okay, misleading question.
What if I like to call the classes dynamically e.g.
def mymethod(class,method)
call(class,method,options)
end
# Both as strings or symbols?
def mymethod(class,method)
const_get(class).send(method)
end
···
On 10/3/06, Daniel Völkerts <daniel@voelkerts.de> wrote:
?
Where call is the Ruby function I'm looking for.
greetings,
--
Daniel Völkerts
Protected by Anti Pesto. -- Wallace & Gromit
--
===Tanner Burson===
tanner.burson@gmail.com
http://tannerburson.com <---Might even work one day...
Jan Svitok schrieb:
Where call is the Ruby function I'm looking for.
Class.send(:method, *options) or
const_get('Class').send(:method, *options)
possibly
const_get('Class').send(:method, *options, &block) but i'm not sure
with this one.
Great const_get('Classname').send is what I'm looking for. TIA!
···
--
Daniel Völkerts
Protected by Anti Pesto. -- Wallace & Gromit