[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03838] Re: Order of overwriting

From: Dave Thomas <Dave@...>
Date: 2000-07-05 16:31:19 UTC
List: ruby-talk #3838
Aleksi Niemel<aleksi.niemela@cinnober.com> writes:

> Now I think it will change into:
> 
> class Foo          # change to a here-comes-a-class-definition(-remember-
>                    # to-scan-through-the-definition-first)
>   def foo
>   end
>   include "Bar"    # whee, here we have it, now we can start to read method
>                    # definitions
> end

Sorry, but you'll have to change again ;-)

Ruby doesn't really differentiate this way. The body of the class
definition is also executable code:

     puts "Before"
     class Dave
       puts "In Dave"
     end
     puts "End"

  => Before
     In Dave
     End

The thing that might be confusing is remembering that Ruby finds its
methods dynamically. It doesn't matter when a method is added to a
class or one of of its ancestors, it's simply a question of what's
present in the ancestor chain at the time the method is called.


Regards


Dave

In This Thread

Prev Next