Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Working with classname that is stored in a string
Bryan Duxbury
8/13/2007 9:27:00 PM
Glen Holcomb wrote:
> Hi all,
One thing you can do is not use a string at all, but pass the class name
constant. If you've got a class like:
class MyClass
...
end
then you can do something like:
filtered_fields = filter_my_fields MyClass, [:field1, :field2]
and it works just fine.
Alternatively, you could use an AR extension like this:
class ActiveRecord::Base
def filtered_fields(*fields)
@attributes.reject{|name, value| fields.include?(name.intern)}
end
end
Haven't run that code, but that should let you do something like
my_ar_instance.filtered_fields(:field1, :field2)
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Working with classname that is stored in a string
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password