Professional Web Applications Themes

running a class from the base class - Ruby

Hi I have examined the test object from the test unit stuff and i cannot work out how the base class executes the main test object... i want to efectively do the same thing. Can anybody give me some tips on how to do this. Effectively i want to: class SpecificArchitecture << BaseArchitecture def main(args) .... end end And when the file is run it just figures out how to make the object and call into main. I currently have a number of derived classes that all have something like: begin xx = SpecificArchitecture.new() xx.main(ARGV) end at the end. Which ...

  1. #1

    Default running a class from the base class

    Hi

    I have examined the test object from the test unit stuff and i cannot
    work out how the base class executes the main test object... i want to
    efectively do the same thing. Can anybody give me some tips on how to do
    this. Effectively i want to:

    class SpecificArchitecture << BaseArchitecture
    def main(args)
    ....
    end
    end

    And when the file is run it just figures out how to make the object and
    call into main. I currently have a number of derived classes that all
    have something like:

    begin
    xx = SpecificArchitecture.new()
    xx.main(ARGV)
    end

    at the end. Which i would like to remove.

    thanks
    Tim

    tim Guest

  2. #2

    Default Re: running a class from the base class


    "tim" <com.au> wrote in message 
    ^^^^^^^^
    If you always want to do this _at the end_ of your program,
    then take a look at the Kernel#at_exit {} method.

    -- shanko


    Shashank Guest

  3. #3

    Default Re: running a class from the base class

    It is hard to understand what you really want, but I'll try to help.

    Perhaps you just need to use some meta-class programming:

    class SpecificArchitecture < BaseArchitecture
    def SpecificArchitecture.main(args)
    ...
    end
    end

    And then you just do:
    begin
    SpecificArchitecture.main(ARGV)
    end

    It means that you call the main function without instanciation.

    I think UnitTest do it another way, but I currently don't know how.

    Lio

    tim wrote: 

    shasckaw Guest

  4. #4

    Default Re: running a class from the base class

    Shashank Date wrote: 
    >
    > ^^^^^^^^
    > If you always want to do this _at the end_ of your program,
    > then take a look at the Kernel#at_exit {} method.
    >
    > -- shanko
    >
    >[/ref]
    thanks -- yes after more spelunking through the test stuff we now have
    something like this:

    ============ file 1 ===========

    require 'y'

    class X < Y
    def blah
    print 'in blah'
    end
    end

    =========== file 2 ============

    class Y
    def self.run()
    ::ObjectSpace::each_object(Class) do |class_object|
    # we only want classes that are above this one...
    if (Y > class_object)
    instance = class_object.new()
    instance.blah()
    end
    end
    end

    at_exit{ exit(Y.run()) }

    ==================================

    I am sure that there are some subtly gothca's in this but it does mean
    that all of my X classes now don't have to have:

    begin
    instance = X.new()
    instance.blah()
    end

    on them all. Theses are obviously much cut down examples -- there is a
    lot more cruft in all real implementations...

    tim Guest

Similar Threads

  1. [PHP-DEV] base class
    By Christian in forum PHP Development
    Replies: 18
    Last Post: January 27th, 03:01 PM
  2. Replies: 1
    Last Post: August 12th, 04:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139