Ask a Question related to Ruby, Design and Development.

  1. #1

    Default anonymous classes

    Hi,

    Could someone please explain to me the concept of an anonymous class?

    I'm talking about this construct:

    class << Foo
    ...
    end

    I'm having a hard time understanding the books and figuring out when I
    might actually want/need to use this.

    Ian
    --
    Ian Macdonald | Keep cool, but don't freeze. -- Hellman's
    System Administrator | Mayonnaise
    [email]ian@caliban.org[/email] |
    [url]http://www.caliban.org[/url] |
    |

    Ian Macdonald Guest

  2. Similar Questions and Discussions

    1. IIS 6.0 with anonymous access and on MX 6.1
      I was having a hard time setting up IIS 6.0 with anonymous access on MX6.1 I was able to run .asp extension but when running .cfm, I got the HTTP...
    2. IIS Not using anonymous impersonation
      Hi, I havea web app that has anonymous accesss enabled. I have specified that IIS should have the credentials of a user in the active directory....
    3. ASP.NET Anonymous Impersonation
      Hi, When you impersonate with anonymous security what is suppose to happen (IIS5 platform). Is it the aspnet_wp.exe process runs under the...
    4. anonymous logon
      I have aproblem. I develop my asp.net site at my pc (named PCMANOS)(running IIS) and I have the SQL Server at another pc (named ATHDC). I've...
    5. How do I log onto anonymous ftp ?
      Hello I have logged onto ftps before, but never an anonymous one. I need to log into ftp://archive.progeny.com/ I can view the files with...
  3. #2

    Default Re: anonymous classes

    Ian Macdonald wrote:
    >Hi,
    >
    >Could someone please explain to me the concept of an anonymous class?
    >
    >I'm talking about this construct:
    >
    >class << Foo
    >...
    >end
    >
    >I'm having a hard time understanding the books and figuring out when I
    >might actually want/need to use this.
    >
    >Ian
    >
    >
    This may be a good starting point:

    [url]http://www.rubygarden.org/ruby?ClassMethods[/url]

    Chad



    Chad Fowler Guest

  4. #3

    Default Re: anonymous classes

    On Tue 01 Jul 2003 at 19:04:23 +0900, Brian Candler wrote:
    > On Tue, Jul 01, 2003 at 08:50:31AM +0900, Ian Macdonald wrote:
    > > Hi,
    > >
    > > Could someone please explain to me the concept of an anonymous class?
    > >
    > > I'm talking about this construct:
    > >
    > > class << Foo
    > > ...
    > > end
    > >
    > > I'm having a hard time understanding the books and figuring out when I
    > > might actually want/need to use this.
    >
    > What you've written is called a "singleton class". I wrote this a while:
    >
    > [url]http://www.rubygarden.org/ruby?SingletonTutorial[/url]
    >
    > It might be helpful and includes a couple of links to more detailled
    > information.
    Thanks. This is an excellent resource and makes things a lot clearer.

    Ian
    --
    Ian Macdonald | Yes, we will be going to OSI, Mars, and
    System Administrator | Pluto, but not necessarily in that order.
    [email]ian@caliban.org[/email] | -- Jeffrey Honig
    [url]http://www.caliban.org[/url] |
    |

    Ian Macdonald Guest

  5. #4

    Default Re: anonymous classes

    > What you've written is called a "singleton class". I wrote this a while:
    >
    > [url]http://www.rubygarden.org/ruby?SingletonTutorial[/url]

    it is very helpful for me too :)

    One question referring to
    "A neat solution then is to create a singleton class for each POP3
    connection as it arrives: "
    How much memory does this technique consume? Are the new methods created
    for each individual instance? Or just something like a lookup table?

    bye!
    Dominik


    Dominik Werder Guest

  6. #5

    Default Re: anonymous classes

    On Wed, Jul 02, 2003 at 05:36:21PM +0900, Dominik Werder wrote:
    > > What you've written is called a "singleton class". I wrote this a while:
    > >
    > > [url]http://www.rubygarden.org/ruby?SingletonTutorial[/url]
    >
    >
    > it is very helpful for me too :)
    >
    > One question referring to
    > "A neat solution then is to create a singleton class for each POP3
    > connection as it arrives: "
    > How much memory does this technique consume? Are the new methods created
    > for each individual instance? Or just something like a lookup table?
    All that happens is that a new proxy class is added to the object, which
    points at the module which you #extended it with. It certainly doesn't copy
    all the methods.

    You can prove this easily enough, by modifying the module *after* you have
    done extend:

    module A
    end
    a = "hello"
    a.extend A
    b = "world"
    b.extend A

    module A
    def foo
    puts "it works"
    end
    end
    a.foo #=> "it works"
    b.foo #=> "it works"

    You can see that the two objects share the same module implementation.

    Regards,

    Brian.

    Brian Candler Guest

Posting Permissions

  • You may not post new threads
  • You may 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