Convention for internal class/module name?

Since Ruby forbid Foo, what is the convention for internal class/method
name? Currently I use Foo
, but I wonder what other people use.

···


dave

What do you mean by “internal”? A class that shouldn’t be accessed by
classes other than the one you are writing (that is, it is an
implementation detail)?

If I write a class, I tend to expect to re-use it, so I rarely do this.
But if I do write a class that other code shouldn’t have access to, I
have been known to put it in a class variable:

class Foo
@@bar = Class.new
@@bar.class_eval do
def foo
puts “foo!”
end
end

def initialize
  @bar = @@bar.new
  @bar.foo()
end

end

or in 1.8:

class Foo
@@bar = Class.new do
def foo
puts “foo!”
end
end
end

Paul

···

On Fri, Mar 05, 2004 at 12:25:42PM +0900, David Garamond wrote:

Since Ruby forbid Foo, what is the convention for internal class/method
name? Currently I use Foo
, but I wonder what other people use.

Paul Brannan wrote:

Since Ruby forbid Foo, what is the convention for internal class/method
name? Currently I use Foo
, but I wonder what other people use.

What do you mean by “internal”? A class that shouldn’t be accessed by
classes other than the one you are writing (that is, it is an
implementation detail)?

Yes. In my case, it’s several different implementation per platform.

module Foo_Win32_
def bar; …; end
end

module Foo_Linux_
def bar; …; end
end

module Foo_Bsd_
def bar; …; end
end

class Foo
case RUBY_PLATFORM
when /win/ then include Foo_Win32_
when /linux/ then include Foo_Linux_
when /bsd/ then include Foo_Bsd_
end

def baz; …; end
def quux; …; end
end

···

On Fri, Mar 05, 2004 at 12:25:42PM +0900, David Garamond wrote:


dave

Is there some reason you can’t more directly:

module FooInternals
case RUBY_PLATFORM
when /win/i
def bar
"Windows"
end
when /bsd/i
def bar
"BSD"
end
when /mac/i
def bar
"Macintosh"
end
end
end

class Foo
include FooInternals
end