Ronnie Aa wrote in post #995580:
> Thanx for your answers. I know: never use global variables ... and no
> monkey patching ...I'll try.
>

Whoa, you can use monkey patching if you follow some guidelines.


> I'm programming for sketchup api. My code structure is like this
>
> module Module
>
> class Do_this
> def initialize()
> end;end;
>
>
> class Do_that
> def initialize()
> end;end;
>
>

The formatting and lack of indenting you are using is unacceptable.


>
> #When I want to execute a command I have to add a button in the GUI of
> Sketchup, like this:
>
>
> cmd = UI::Command.new("Do this")  {Module::Do_this.new()}
> UI.menu("Plugins").add_item(cmd)
>
> end#module
> #-------------------------------------------------------
> So as markus suggested
>
> class Test
>   def initialize
>     @array = [10,10]
>   end
>
>   def product
>     @array.inject(1) { |s,v| s *= v }
>   end
> end
>
> And than run *outside* the class:
>
> object = Test.new
> object.product  # => 100
>
>
> Is in my case impossible: it has to run *inside* a class
>

What does that mean?



> Just did some quick reading about procs, is that an option???
>
> For extra clearness:
>
> My class Do_this and my class Do_that both have to use that method..
> They both use the same variable and both have to apply the same
> operations on that variable (amongst other things of course)..
>
>
> Please help

It sounds like you are trying to reinvent someone's wheel.  Anything you 
are trying to do has already been done before--or you are going about it 
the wrong way.

-- 
Posted via http://www.ruby-forum.com/.