Clemens Hintze <c.hintze / gmx.net> wrote:
>
>On  7 Jan, Holden Glova wrote:
[...]
>do not feel to sad! It is not such a big issue. What makes it a bit
>difficult to explain, however, is that due to Ruby's flexibility and
>power, the answer comes in three flavours, at least. You know, although
>Ruby is a real and complete OOL, it let *you* decide to use which
>paradigm to program in. It do not force you to use OOP at all.
>
>The three paradigms, Ruby supports and I want to mention, are:
                                    ^^^^^^^^^^^^^^^^^^^^^
It supports more of course. :-)

>o Procedural programming
>   In this paradigm you use classes as struct/record like datatype
>   definition. [...]
>
>o OOP (Class based)
>   Here modules have additional sense. You can use them like in the
>   procedural programming, explained above, but you can use them also to
>   group functionalities together. [...]
>
>o Classless OO
>   That paradigm is also called prototype based programming. Here you
>   really didn't need classes to do anything in your program. While in
>   'classic' OO, you need to create a class to describe the objects
>   (means instances) you want to create, in classless OO you simply build
>   concrete, ready-to-use objects with desired structure and behavior. If
>   you need more then one instantiation of such an object, you simply
>   clone an already existing one and have two of them then.
[...]

Ruby also supports functional techniques.  You call proc()
to produce a procedure, and then call it many times.  The
following quick hack shows what those techniques look like,
though it is a port of a quick example I did in Perl and I
don't know if it is how you would want to solve this problem
in Ruby:

  #! /usr/local/bin/ruby -w

  def nested_for (fn, *arg)
    bind_param(fn, *arg)[]
  end

  def bind_param(fn, my_range, *more_args)
    bound_fn = proc { |*args|
      for arg in my_range do
        fn[arg, *args]
      end
    }
    (0 == more_args.length()) ?
      bound_fn :
      bind_param(bound_fn, *more_args)
  end

  nested_for \
    proc  {|*arg| puts arg.join(" ")} , \
    1..2, 'a'..'c', 'A'..'D'

>Of course, nobody will prevent you from mixing these all in your program
>;-)

Functional as well. :-)

For the record, Python does not support functional
techniques like the above.  This simple omission is
one reason why I never seriously considered using
Python instead of Perl.  Oh, I saw the Python people
claim to be able to do anything I can do with closures
without, but that isn't really true.

Cheers,
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com