Hi --

On Thu, 13 Mar 2008, Mario Ruiz wrote:

> Actually what I want is to include an scenario with all my global
> variables and if I want another scenario I can include it and all the
> global variables will change.
> module Scenarios
>   module MyFirstSc
>      $web="http://www.elmundo.es"
>      $sqlSearch="select video from datab"
>      $user="Pep"
>      $password="xxx"
>   end
>   module MySecondSc
>      $web="http://www.elmundo.es"
>      $sqlSearch="select audiodefault from datab"
>      $user="Bee"
>      $password="2x8"
>   end
> end
>
> In my test cases I'll have in the first line for example:
> include Scenarios::MySecondSc
> and if I want to change the scenario I only have to change this line:
> include Scenarios::MyFirstSc
>
> How can I do it without including an extraline with a method?
> I know I could do something like:
> module Scenarios
>   module MyFirstSc
>     def getValues
>        $web="http://www.elmundo.es"
>        $sqlSearch="select video from datab"
>        $user="Pep"
>        $password="xxx"
>     end
>   end
> ...
> end
>
> and in the first line we'll write:
> include Scenarios::MyFirstSc
> Scenarios::MyFirstSc.getValues()
>
>
> But I don't like this way I would like to do it in only one line... is
> it possible???

See Chris's answer: use constants, and include the module you want.
I've been programming in Ruby for 7.5 years and I have no clear memory
of ever having created a global variable. I imagine I have once or
twice, but it's very, very unlikely that you need to do it or that
it's the best way to do it in this case.


David

-- 
Upcoming Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS, April 14-17 2008, New York City
   CORE RAILS, June 24-27 2008, London (Skills Matter)
See http://www.rubypal.com for details. Berlin dates coming soon!