[#349422] Date.parse('17:26:33 Oct 31, 2009') returns invalid date — Jacob Gorban <jacob.gorban@...>

Hi,

13 messages 2009/11/01

[#349519] All Gems Down? — Joshua Ballanco <jballanc@...>

I think I must be the only one using allgems.ruby-forum.com. It seems

17 messages 2009/11/03

[#349527] Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...>

I=E2=80=99m starting to dip my toes in non-Ruby coding (for performance rea=

13 messages 2009/11/03
[#349564] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — Ryan Davis <ryand-ruby@...> 2009/11/03

[#350186] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...> 2009/11/11

Ryan Davis:

[#350196] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — Roger Pack <rogerpack2005@...> 2009/11/11

> — Shot, who’s off to play with RubyToC now. :)

[#350228] Re: Ruby Inline over two times slower under 1.9 than under 1.8? — "Shot (Piotr Szotkowski)" <shot@...> 2009/11/11

Roger Pack:

[#349640] Odd : a = Hash.new(Hash.new) — Aldric Giacomoni <aldric@...>

irb(main):086:0> a = Hash.new(Hash.new)

13 messages 2009/11/04
[#349641] Re: Odd : a = Hash.new(Hash.new) — Aldric Giacomoni <aldric@...> 2009/11/04

Aldric Giacomoni wrote:

[#349685] Create HTML files using RUBY — Krithika San <skrithikaa@...>

Hi,

23 messages 2009/11/04
[#349690] Re: Create HTML files using RUBY — Marnen Laibow-Koser <marnen@...> 2009/11/04

Krithika San wrote:

[#349691] Re: Create HTML files using RUBY — Krithika San <skrithikaa@...> 2009/11/04

Hi Marnen,

[#349692] Re: Create HTML files using RUBY — Marnen Laibow-Koser <marnen@...> 2009/11/04

Krithika San wrote:

[#349720] Executing one of several ruby objects — "dhf0820@..." <dhf0820@...>

I am trying to write a program that will load a series of DSLs (ruby

11 messages 2009/11/05

[#349849] RCR enumerable extra into core — Roger Pack <rogerpack2005@...>

I'm considering suggesting that the base functionality for the

25 messages 2009/11/08
[#349853] Re: RCR enumerable extra into core — "David A. Black" <dblack@...> 2009/11/08

Hi --

[#349996] Re: RCR enumerable extra into core — Roger Pack <rogerpack2005@...> 2009/11/09

[#349888] Using Nokogiri — jzakiya <jzakiya@...>

I'm trying to scrape some data off websites using nokogiri

18 messages 2009/11/08

[#349926] FileString - request for comments — apeiros@...

Hi there

15 messages 2009/11/09
[#349931] Re: FileString - request for comments — James Edward Gray II <james@...> 2009/11/09

On Nov 8, 2009, at 7:47 PM, apeiros@gmx.net wrote:

[#349987] Berkeley DB BDB Install on Windows — david <davidhooey@...>

I've been scripting in Ruby (and Rails) for about two years now, but

14 messages 2009/11/09

[#350007] Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com>

Newbie here:

45 messages 2009/11/09
[#350017] Re: Good or best way to allocate a large array — Marnen Laibow-Koser <marnen@...> 2009/11/09

Ralph Shnelvar wrote:

[#350019] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Marnen,

[#350023] Re: Good or best way to allocate a large array — Marnen Laibow-Koser <marnen@...> 2009/11/09

Ralph Shnelvar wrote:

[#350029] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Marnen,

[#350042] Re: Good or best way to allocate a large array — "Florian Frank" <flori@...> 2009/11/09

Ralph Shnelvar wrote:

[#350045] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/09

Florian,

[#350047] Re: Good or best way to allocate a large array — Rick DeNatale <rick.denatale@...> 2009/11/09

On Mon, Nov 9, 2009 at 5:46 PM, Ralph Shnelvar <ralphs@dos32.com> wrote:

[#350048] Re: Good or best way to allocate a large array — Ralph Shnelvar <ralphs@...32.com> 2009/11/10

Rick,

[#350053] Re: Good or best way to allocate a large array — Florian Gilcher <flo@...> 2009/11/10

Hi,

[#350142] Calling a subprocess with specific arguments and capturing its output? — Dan Q <quinxex@...>

Hi. I haven't written Ruby in a while, and I was wondering if someone

9 messages 2009/11/10

[#350147] Roman Numerals (Arrgh!) — Rick Barrett <chngth3wrld@...>

I have a homework assignment where I have to convert an inputted integer

22 messages 2009/11/10
[#350150] Re: Roman Numerals (Arrgh!) — Rob Biedenharn <Rob@...> 2009/11/11

On Nov 10, 2009, at 6:56 PM, Rick Barrett wrote:

[#350152] Re: Roman Numerals (Arrgh!) — Gennady Bystritsky <Gennady.Bystritsky@...> 2009/11/11

On Nov 10, 2009, at 5:37 PM, Rob Biedenharn wrote:

[#350156] Re: Roman Numerals (Arrgh!) — Rob Biedenharn <Rob@...> 2009/11/11

On Nov 10, 2009, at 8:49 PM, Gennady Bystritsky wrote:

[#350159] Re: Roman Numerals (Arrgh!) — Gennady Bystritsky <Gennady.Bystritsky@...> 2009/11/11

[#350290] DRYing a Regex — RichardOnRails <RichardDummyMailbox58407@...>

I've got a routine that works fine at building an array of upper-case

42 messages 2009/11/12
[#350311] Re: DRYing a Regex — RichardOnRails <RichardDummyMailbox58407@...> 2009/11/13

On Nov 12, 6:50=A0pm, James Edward Gray II <ja...@graysoftinc.com>

[#350367] Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

RichardOnRails wrote:

[#350368] Re: Naming conventions -- was: Re: DRYing a Regex — James Edward Gray II <james@...> 2009/11/14

On Nov 13, 2009, at 10:11 PM, Marnen Laibow-Koser wrote:

[#350369] Re: Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

James Edward Gray II wrote:

[#350415] Re: Naming conventions -- was: Re: DRYing a Regex — "David A. Black" <dblack@...> 2009/11/14

Hi --

[#350426] Re: Naming conventions -- was: Re: DRYing a Regex — Marnen Laibow-Koser <marnen@...> 2009/11/14

David A. Black wrote:

[#350359] Trajectories — Thijs Leeflang <t_leeflang@...>

hello,

60 messages 2009/11/13
[#350444] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/14

Thijs Leeflang wrote:

[#350446] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 14 Nov 2009, at 23:40, Marnen Laibow-Koser wrote:

[#350447] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Eleanor McHugh wrote:

[#350449] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 15 Nov 2009, at 00:42, Marnen Laibow-Koser wrote:

[#350451] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Eleanor McHugh wrote:

[#350509] Re: Trajectories — Rick DeNatale <rick.denatale@...> 2009/11/15

On Sat, Nov 14, 2009 at 8:19 PM, Marnen Laibow-Koser <marnen@marnen.org> wr=

[#350523] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/15

Rick Denatale wrote:

[#350524] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/15

On 15 Nov 2009, at 23:02, Marnen Laibow-Koser wrote:

[#350529] Re: Trajectories — Todd Benson <caduceass@...> 2009/11/16

On Sun, Nov 15, 2009 at 5:32 PM, Eleanor McHugh

[#350532] Re: Trajectories — Eleanor McHugh <eleanor@...> 2009/11/16

On 16 Nov 2009, at 01:12, Todd Benson wrote:

[#350538] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Eleanor McHugh wrote:

[#350577] Re: Trajectories — Paul Smith <paul@...> 2009/11/16

On Mon, Nov 16, 2009 at 2:57 AM, Marnen Laibow-Koser <marnen@marnen.org> wr=

[#350593] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Paul Smith wrote:

[#350600] Re: Trajectories — Paul Smith <paul@...> 2009/11/16

On Mon, Nov 16, 2009 at 3:18 PM, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350602] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/16

Paul Smith wrote:

[#350628] Re: Trajectories — Caleb Clausen <vikkous@...> 2009/11/17

On 11/16/09, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350629] Re: Trajectories — Marnen Laibow-Koser <marnen@...> 2009/11/17

Caleb Clausen wrote:

[#350645] Re: Trajectories — Caleb Clausen <vikkous@...> 2009/11/17

On 11/16/09, Marnen Laibow-Koser <marnen@marnen.org> wrote:

[#350454] How do I get a random number between two random numbers? — Alex Untitled <somebodydc691n@...>

I want to create a program that asks you to guess a number between two

12 messages 2009/11/15

[#350476] Traversing the contents of a proc (for a DSL) — Siemen Baader <siemenbaader@...>

Hi List,

11 messages 2009/11/15

[#350485] Using activerecord with mysql — Rob Mauchel <rmauchel@...>

Hi All,

13 messages 2009/11/15

[#350526] Newbie question: Defining a numeric type — Seebs <usenet-nospam@...>

I have a type which has a bit of internal magic, but fundamentally, I want

32 messages 2009/11/16

[#350535] Any official name for Ruby's class which makes "class methods"? — Hunt Jon <jona.hunt777@...>

We all know Ruby really doesn't have class methods.

20 messages 2009/11/16
[#350539] Re: Any official name for Ruby's class which makes "class me — Marnen Laibow-Koser <marnen@...> 2009/11/16

Hunt Jon wrote:

[#350682] Re: Any official name for Ruby's class which makes "class me — "David A. Black" <dblack@...> 2009/11/17
[#350689] Re: Any official name for Ruby's class which makes "class me — Marnen Laibow-Koser <marnen@...> 2009/11/17

David A. Black wrote:

[#350698] Re: Any official name for Ruby's class which makes "class me — "David A. Black" <dblack@...> 2009/11/17

[#350590] Google Wave: A new type of "Ruby Quiz" ? — Aldric Giacomoni <aldric@...>

Google Wave is, according to Google, "the new email". It combines email,

21 messages 2009/11/16

[#350594] something went wrong — Dev Tri <divyanshutri@...>

16 messages 2009/11/16

[#350669] What is the difference between the two following pieces of c — Doney Kaka <doneysr@...>

Don't really know where to go with this one, but I gotta know...

10 messages 2009/11/17

[#350679] Class inside a Method Body — Mike Stephens <rubfor@...>

I have a class that works fine if I declare it outside of anything. If

15 messages 2009/11/17

[#350705] Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...>

Hello all,

17 messages 2009/11/17
[#350709] Re: Special characters in csv header using fastercsv — James Edward Gray II <james@...> 2009/11/17

On Nov 17, 2009, at 10:24 AM, John Mcleod wrote:

[#350710] Re: Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...> 2009/11/17

James,

[#350712] Re: Special characters in csv header using fastercsv — James Edward Gray II <james@...> 2009/11/17

On Nov 17, 2009, at 10:38 AM, John Mcleod wrote:

[#350719] Re: Special characters in csv header using fastercsv — John Mcleod <john.mcleod@...> 2009/11/17

I'm not sure if the placement is correct but I'm still getting "Error

[#350810] Exact (LISP-ish) calculations in Ruby? — Aldric Giacomoni <aldric@...>

Has anyone written a gem for exact calculations? The kind one would find

25 messages 2009/11/18

[#350829] Ruby/tk Help Please — Sean Ob <sob4ever33@...>

I am a complete beginner when it comes to programming and i need some

20 messages 2009/11/18
[#350830] Re: Ruby/tk Help Please — Marnen Laibow-Koser <marnen@...> 2009/11/18

Sean Ob wrote:

[#350924] How to strip ruby comments in a ruby line of code? — Alexandre Mutel <alexandre_mutel@...>

Short description : My question is : do you know any available method,

17 messages 2009/11/19

[#350969] Re-opening an existing module and changing a method — Aldric Giacomoni <aldric@...>

"I hear and I forget; I see and I remember; I do and I understand."

11 messages 2009/11/19

[#351010] RubyForge gem index is no more — Tom Copeland <tom@...>

Hello -

14 messages 2009/11/20

[#351084] Distinct Sets (#225) — Daniel Moore <yahivin@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

21 messages 2009/11/21
[#351111] Re: [QUIZ] Distinct Sets (#225) — brabuhr@... 2009/11/21

On Fri, Nov 20, 2009 at 9:23 PM, Daniel Moore <yahivin@gmail.com> wrote:

[#351170] Re: [QUIZ] Distinct Sets (#225) — Rob Biedenharn <Rob@...> 2009/11/22

[#351171] Re: Distinct Sets (#225) — lith <minilith@...> 2009/11/22

> http://gist.github.com/240457

[#351279] Re: Distinct Sets (#225) — Rob Biedenharn <Rob@...> 2009/11/23

On Nov 22, 2009, at 1:51 AM, lith wrote:

[#351137] Order of evaluation and precedence — Seebs <usenet-nospam@...>

In _The Ruby Programming Language_, it is asserted that order of evaluation

11 messages 2009/11/21

[#351245] More on psuedo arrays; Better way? — Ralph Shnelvar <ralphs@...32.com>

Newbie here:

15 messages 2009/11/23
[#351266] Re: More on psuedo arrays; Better way? — Marnen Laibow-Koser <marnen@...> 2009/11/23

Ralph Shnelvar wrote:

[#351267] Re: More on psuedo arrays; Better way? — Brian Candler <b.candler@...> 2009/11/23

Marnen Laibow-Koser wrote:

[#351271] Re: More on psuedo arrays; Better way? — Ralph Shnelvar <ralphs@...32.com> 2009/11/23

BC> Marnen Laibow-Koser wrote:

[#351297] ideas for a "parameter sweep" program? — Diego Virasoro <diego.virasoro@...>

Hello,

11 messages 2009/11/23

[#351328] Warning: instance variable @foo not initialized — Seebs <usenet-nospam@...>

Running some simple tests with Prawn, I am getting thousands of lines

13 messages 2009/11/24

[#351367] Difference between << and += for Strings and Arrays. Bug? — Pieter Hugo <pieter@...>

Hi

14 messages 2009/11/24
[#351373] Re: Difference between << and += for Strings and Arrays. Bug? — Tom Stuart <tom@...> 2009/11/24

2009/11/24 Pieter Hugo <pieter@internext.co.za>:

[#351377] Re: Difference between << and += for Strings and Arrays. Bug? — Pieter Hugo <pieter@...> 2009/11/24

Hi Guys

[#351426] Ruby internals & other questions — Ralph Shnelvar <ralphs@...32.com>

Is there a document or website that describes how Ruby works?

17 messages 2009/11/25

[#351448] Ruby a good choice for CGI? — Nick Dr <nickhannum@...>

Ive been messing around with Ruby for a few weeks now, and I'm fairly

28 messages 2009/11/25
[#351452] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 01:12:19 pm Nick Dr wrote:

[#351453] Re: Ruby a good choice for CGI? — Marnen Laibow-Koser <marnen@...> 2009/11/25

David Masover wrote:

[#351455] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 02:38:32 pm Marnen Laibow-Koser wrote:

[#351456] Re: Ruby a good choice for CGI? — Judson Lester <nyarly@...> 2009/11/25

On Wed, Nov 25, 2009 at 12:52 PM, David Masover <ninja@slaphack.com> wrote:

[#351461] Re: Ruby a good choice for CGI? — David Masover <ninja@...> 2009/11/25

On Wednesday 25 November 2009 03:00:49 pm Judson Lester wrote:

[#351508] Ruby byte access to disk sectors like dd does — Gary Hasson <gary@...>

I have been unable to find any reference to Ruby methods that provide

16 messages 2009/11/26

[#351548] Class variables, instance variables, singleton; Ruby v. C++ — Ralph Shnelvar <ralphs@...32.com>

Newb here coming from C++

31 messages 2009/11/27
[#351570] Re: Class variables, instance variables, singleton; Ruby v. C++ — Steve Wilhelm <steve@...831.com> 2009/11/28

Ralph Shnelvar wrote:

[#351579] Re: Class variables, instance variables, singleton; Ruby v. C++ — "David A. Black" <dblack@...> 2009/11/28

Hi --

[#351586] Re: Class variables, instance variables, singleton; Ruby v. C++ — Ralph Shnelvar <ralphs@...32.com> 2009/11/28

DAB> And of course this is one of the (many) problems with class variables:

[#351572] Local variables can't be accessed from outside, right? — Michael Winterstein <parzival@...>

Hi, I've been trying to figure out metaprogramming and I've mostly got

9 messages 2009/11/28

[#351637] Best way to distribute an app — Omar Campos <hypermeister@...>

Hello everyone,

16 messages 2009/11/29
[#351682] Re: Best way to distribute an app — David Masover <ninja@...> 2009/11/29

On Saturday 28 November 2009 09:03:12 pm Omar Campos wrote:

[#351655] ruby language parser in ruby — Brian Candler <b.candler@...>

I'm looking for a ruby language parser written in ruby, that I can hack

27 messages 2009/11/29

[#351753] have a problem with the loops and variable — Sajjad Po <magicc0d3r@...>

Hi Friends.

20 messages 2009/11/30
[#351756] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/11/30

[#351788] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/01

Michael Linfield wrote:

[#351796] Re: have a problem with the loops and variable — Sajjad Po <magicc0d3r@...> 2009/12/01

thank you friends.

[#351798] Re: have a problem with the loops and variable — Sajjad Iran <magicc0d3r@...> 2009/12/01

I want create a program like this.

[#351833] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/12/01

Sajjad Po wrote:

[#351835] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/01

Michael Linfield wrote:

[#351840] Re: have a problem with the loops and variable — Michael Linfield <globyy3000@...> 2009/12/01

For something small such as testing lets say a million keys, the

[#351842] Re: have a problem with the loops and variable — Marnen Laibow-Koser <marnen@...> 2009/12/02

Michael Linfield wrote:

[#351755] Problem trying to get a constant with correct scope — Alexandre Mutel <alexandre_mutel@...>

I'm trying to get a constant inside a class (but i have to do it outside

11 messages 2009/11/30

Re: Class variables, instance variables, singleton; Ruby v. C++

From: David Masover <ninja@...>
Date: 2009-11-30 09:04:25 UTC
List: ruby-talk #351711
On Monday 30 November 2009 01:43:38 am Ralph Shnelvar wrote:
> DAB> This is the so-called "class instance variable", which is really just
> DAB> "an instance variable that happens to belong to a Class object". It's
> DAB> common to use the phrase "class instance variable", but it's just a
> DAB> way of clarifying what you mean. There's no separate "class instance
> DAB> variable" language-level construct.
> 
> So ... let's see if I get this.

Sorry, I don't remember enough C++ to help you here.

> It appears to me that "class" is a jumble of two kinds of very
> different semantics.
> 
> There is the notion of a class as a template for instances of the
> class.

Correct.

> Then there is a very different notion of a sorta static class that
> has it's own variables that do not propagate to instances; and may
> (@@x) or may not (@x) propagate and be accessile to static subclasses
>  inherited from the static superclass.

Well, my advice is to forget that @@x exists at all -- I've never properly 
understood how it propagates or how to properly manage it, and it seems to be 
an invitation for disaster.

But you're half-right...

> A lot to wrap one's head around.  I assume that there are good design
> reasons to jumble these two concepts together in the semantics of
> "class".

It's very simple, really:

In Ruby, EVERYTHING is an object.

You may have seen this cute example before:

class Fixnum
  def + other
    5
  end
end

That's right, ordinary integers are just objects, and arithmetic operators are 
just methods, which can be overridden. And if you type the above into IRB, you 
can prove that 2+2==5, for very strange definitions of +.

But this is the crucial concept: Numbers are objects. True and false are 
objects. Even null is an object -- the object is called nil, and it is an 
instance of NilClass. Files are objects. Sockets are objects. Constants are 
objects. Symbols are objects.

EVERYTHING is an object. So, EVERYTHING has the semantics of an object. In 
addition, everything that's an object is an instance of a class.

Or, to put it another way: The number 5 has the semantics of an ordinary 
integer, but also the semantics of an object. You can prove it to yourself:

class Fixnum
  attr_accessor :message
end

That's right, numbers can have methods, even instance variables! Type that 
into IRB and try this:

5.message = 'Hello, world!'
4.message
5.message

If you can wrap your head around this concept, it shouldn't surprise you too 
much that classes are objects, and modules are objects, too. Classes are 
instance of the class "Class", while modules are instances of the class 
"Module".

So the idea of "static" is really unnecessary baggage in this discussion. If 
you're looking for something similar, I've already presented one option, but 
it's not really "static", just like an each loop isn't really a foreach loop. 
Here's a complete answer to the question "How many objects of type Foo are 
there?" in the traditional C++ style:


class Foo
  class << self
    # These are about the Foo class itself, as an object.
    # Any methods here are methods on the Foo object itself,
    # not instances of Foo:
    def count
      @count ||= 0
    end
    attr_writer :count
    def finalizer
      @finalizer ||= lambda do
        self.count -= 1
      end
    end
  end

  # These are instance methods on the Foo class:
  def initialize
    self.class.count += 1
    ObjectSpace.define_finalizer(self, self.class.finalizer)
  end
end


As you can see, finalizers are kind of cumbersome to use (so don't use them, 
you almost certainly don't need them), but they should work. Whenever the 
garbage collector finally eats those objects, the count will go down. (You can 
force the matter by calling GC.start, but that's for debugging purposes only!)

Now, what's going on here? Probably the most confusing part is this statement:

class << self

What is that doing? That's opening what's called the metaclass of an object. 
Every object has a metaclass, which is easiest to think of like this: When you 
call Foo.new, you get an object which inherits from a class unique to that 
object, which in tern inherits from Foo.

It's actually not quite like that, but that gives you an idea of what's going 
on. For example, try this:

a = 'foo'
def a.bar
  5
end

If you understand what that does, then this does the exact same thing:

a = 'foo'
class << a
  def bar
    5
  end
end

Now, what is self inside the Foo class? It's the Foo object itself.

The simplest way to explain what all that code is doing is to remember that I 
was just using Foo as an object because it seemed a convenient place to store 
values common to all Foos. I could just as easily have done this (for the non-
finalized version):

class Foo
  Count = 0
  def initialize
    Count += 1
  end
end

It'll whine because I'm reassigning constants, but you see the point. I mean, 
I could also do this:

FooCount = 0
class Foo
  def initialize
    FooCount += 1
  end
end

It's just that the Foo object is already there, and makes sense for this 
purpose.


Also, if you haven't seen this before, don't let it frighten you:

@count ||= 0

That's providing a default value for @count. When you execute that code, it 
checks whether @count has a positive value -- if it doesn't, it assigns 0 to 
@count. Either way, the (possibly new) value of @count will be returned.



So regarding your musings as to whether there's a good design reason, I'd 
argue yes and no. No, it really doesn't seem good design, at first glance, 
that numbers can have instance variables, because why would that ever, ever, 
be a good idea?

But yes, it actually gives a nice uniform model. Again, EVERYTHING is an 
object, so EVERYTHING has methods, instance variables, a metaclass, and so on.

In This Thread