Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #7022
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Module Pattern in Ruby |
| Date | 2014-09-10 22:29 +0200 |
| Message-ID | <c7bqkmFgl70U1@mid.individual.net> (permalink) |
| References | <608f2172-203a-4a3e-9d0b-82a49c626139@googlegroups.com> |
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 <<self; attr_accessor :x; end; end => 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
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
Module Pattern in Ruby deltanoob <dexterp@gmail.com> - 2014-09-10 02:45 -0700 Re: Module Pattern in Ruby Robert Klemme <shortcutter@googlemail.com> - 2014-09-10 22:29 +0200
csiph-web