can we add a string to a instance varaiable....

HI ,

can we add a string to an instance variable like


because i've the same query to be executed for both User and Post, for
every month jan..dec.

  so can i write a method which contains

@jan+"#{name}"=#{Name}.find(:all) name--> either post or user that
i pass to the method....

and how to convert Name i,e; string into object?

  plz reply........


Ryan Bigg wrote:


i need some thing like

@jan is an instance varaible and can i add a string like name="hi"
to the instance variable like


is it possible and even i want to know can we convert a string object
into object(instance)?

  like we do in java to_String() and to_Object()


Why? What are you trying to accomplish?

Ryan Bigg wrote:

Why? What are you trying to accomplish?


Appreciated my help?
Recommend me on Working With Rails

   yeah, to be clear .....

i've 2 methods one for posts and another for users...
i'd like to get number of users for every month and same for number of
posts for every month..

for that i had written like

               @januser=User.find(:all,:condition=>["created_at between
? AND ?","#{changedyear}-01-01","#{changedyear}-01-31"])
like this for every month as i don't 've a feild name month in

and the same query can be used by post like
  @janpost=Post.find(:all,:condition=>["created_at between ? AND

and changedyear is a dynamic one...........

so the query is same for both of them...

so can i write

@jan+"#{name}"="#{Name}".find(:all,:condition=>["created_at between ?
AND ?","#{changedyear}-01-01","#{changedyear}-01-31"]) where name may be
post or user ....

Well I thin you're looking for instance_variable_set and constantize,
but personally I'd put most of that method in the post/user model (and
probably return a hash keyed by the month you're looking at).


The finder methods generated by ActiveRecord take a range (I think), so you can find the start date for January and then the end date and do something like this: