# Static variables

**URL:** <https://www.ruby-forum.com/t/static-variables/166438>\
**Category:** Rails\
**Created:** [April 25, 2009, 6:49am UTC](https://www.ruby-forum.com/t/static-variables/166438 "2009-04-25T06:49:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [April 25, 2009, 6:49am UTC](https://www.ruby-forum.com/t/static-variables/166438/1 "2009-04-25T06:49:52Z")

</div>

## Hi In controller I have def role\_wise\_summary\_graph\_render @graph1 = open\_flash\_chart\_object(300,200, “#{summary\_graph\_path(:role\_name =\> ‘Role1’)}”, true) @graph2 = open\_flash\_chart\_object(300,200, “#{summary\_graph\_path(:role\_name =\> ‘Role2’)}”, true) respond\_to do |format|

```
    end

```

end

###summary\_graph\_path =\> :action =\> draw\_role\_level\_summary\_graph  
def draw\_role\_level\_summary\_graph

@role1\_array,@role2\_array,@open\_requests =  
MyRequest.get\_role\_wise\_summary\_graph\_data

```
if params[:role_name] == 'Role1'
  role_data_array = @role1_array
elsif params[:role_name] == 'Role2'
  role_data_array = @role2_array
end
 graph =

```

role\_level\_graph(params[:role\_name],role\_data\_array,@open\_requests)  
render :text =\> graph.render  
end

```
Here in above role_level_graph is a library function finally

```

responsible for drawing graph The above code is working  
My question is in the above how can I make the varibales  
@role1\_array,@role2\_array,@open\_requests static so that only once  
MyRequest.get\_role\_wise\_summary\_graph\_data get called Because I need it  
only once But happens now is all the two times this def gets called How  
can I avoid this to call this only once and get the details

Thanks in advance  
SSijo
