Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Module Pattern in Ruby Date: Wed, 10 Sep 2014 22:29:08 +0200 Lines: 35 Message-ID: References: <608f2172-203a-4a3e-9d0b-82a49c626139@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net iou/zt/IihdOpkHcWlpznwO+3HIV4nQfVyfv0IVTqmx5W2uM8= Cancel-Lock: sha1:Q8BGhyUX4pJ1Q1l3cCG9tiZoMvw= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 In-Reply-To: <608f2172-203a-4a3e-9d0b-82a49c626139@googlegroups.com> Xref: csiph.com comp.lang.ruby:7022 On 10.09.2014 11:45, deltanoob wrote: > I'm looking for a good tutorial on the "ruby way" to implement the module pattern in ruby. > > http://en.wikipedia.org/wiki/Module_pattern "In software engineering, the module pattern is a design pattern used to implement the concept of software modules, defined by modular programming, in a programming language with incomplete direct support for the concept." Now, Ruby _has_ support for modules - there is even a keyword of that name. :-) If you need to store state in a module in the same way as can be done in a Modula or PL/SQL package you can simply define accessors: irb(main):001:0> module Foo; @x = 1; class < nil irb(main):002:0> Foo.x => 1 irb(main):003:0> Foo.x = 99 => 99 irb(main):004:0> Foo.x => 99 irb(main):005:0> Foo.x =3 => 3 irb(main):006:0> Foo.x => 3 Note: the initialization of @x is not necessary. Kind regards robert