Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3643

Re: calling methods, beginner help

From Markus Schirp <mbj@seonic.net>
Newsgroups comp.lang.ruby
Subject Re: calling methods, beginner help
Date 2011-04-28 13:03 -0500
Organization Service de news de lacave.net
Message-ID <20110428180356.GA9583@mbj> (permalink)
References <626238bd776ed0898a473c7a16e02fb5@ruby-forum.com> <560a5f2c1a7578882b0fd9ce72f43724@ruby-forum.com>

Show all headers | View raw


Hola,

Since I see you got a programming background, but you are *just* new
to ruby, I'd suggest you should read some code from guys with IMHO
*very* good ruby coding style. (not mine *g*)

Try to read code from a random advanced ruby library, 
most of your questions about API-Design will be answered!

You can start with one of my favorite libraries: datamapper

https://github.com/datamapper/dm-core

I did not got the point in your code so I cannot help you without a
better description about what you are trying to do ;)

--

Markus

On Fri, Apr 29, 2011 at 02:44:31AM +0900, Ronnie Aa wrote:
> Thanx for your answers. I know: never use global variables ... and no 
> monkey patching ...I'll try.
> 
> 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;
> 
> 
> 
> #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
> 
> 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
> 
> -- 
> Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

calling methods, beginner help Ronnie Aa <liquid98@gmail.com> - 2011-04-28 12:06 -0500
  Re: calling methods, beginner help Markus Schirp <mbj@seonic.net> - 2011-04-28 12:14 -0500
  Re: calling methods, beginner help 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 12:23 -0500
  Re: calling methods, beginner help Ronnie Aa <liquid98@gmail.com> - 2011-04-28 12:44 -0500
    Re: calling methods, beginner help Markus Schirp <mbj@seonic.net> - 2011-04-28 13:03 -0500
    Re: calling methods, beginner help 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-28 13:03 -0500
    Re: calling methods, beginner help Brian Candler <b.candler@pobox.com> - 2011-04-28 15:29 -0500
  Re: calling methods, beginner help Ronnie Aa <liquid98@gmail.com> - 2011-04-28 13:40 -0500
  Re: calling methods, beginner help Ronnie Aa <liquid98@gmail.com> - 2011-04-28 16:05 -0500
    Re: calling methods, beginner help Brian Candler <b.candler@pobox.com> - 2011-04-29 03:02 -0500
      Re: calling methods, beginner help Ronnie Aa <liquid98@gmail.com> - 2011-04-29 04:27 -0500
        Re: calling methods, beginner help Brian Candler <b.candler@pobox.com> - 2011-04-29 13:19 -0500
        Re: calling methods, beginner help Stu <stu@rubyprogrammer.net> - 2011-04-29 15:24 -0500

csiph-web