[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

nested namespaces: so many spaces

jandot

11/12/2007 4:09:00 PM

Hi all,

For one of my libraries, I have to create nested namespaces such as
Bio::Graphics::Panel::Track::Feature. Code for these is contained in
separated files: the code for Bio::Graphics::Panel in panel.rb, the
code for Bio::Graphics::Panel::Track in track.rb and
Bio::Graphics::Panel::Track::Feature in feature.rb.

Unfortunately, I don't know a way of putting the whole namespace on
one line in e.g. feature.rb. As a result, every single line of code
has to be preceded with 12 spaces. But this can become cumbersome and
is basically a waste of, well, space...

Here's what it looks like:

...module Bio
.....module Graphics
.......class Panel
.........class Track
...........class Feature
.............# all
.............# the
.............# code
.............# needs
.............# 12 spaces
...........end
.........end
.......end
.....end
...end

What I _could_ do is something like this:

...module Bio
...module Graphics
...class Panel
...class Track
...class Feature
.....# all
.....# the
.....# code
.....# just
.....# needs
.....# 4 spaces
...end
...end
...end
...end
...end

But then you end up with just a whole string of "end"s at the bottom
of your file. Isn't there a way to define the complete namespace in
one go on one line?

I've tried things like
...class Bio::Graphics::Panel::Track::Feature
.....def initialize()
.....end
...end

But that didn't work. Any suggestions welcome.

Thanks,
jan.

4 Answers

furtive.clown

11/12/2007 5:02:00 PM

0

Bio = Module.new
Bio::Graphics = Module.new
Bio::Graphics::Panel = Class.new
Bio::Graphics::Panel::Track = Class.new
Bio::Graphics::Panel::Track::Feature = Class.new

class Bio::Graphics::Panel::Track::Feature
def foo
puts "foo"
end
end

Bio::Graphics::Panel::Track::Feature.new.foo # => "foo"


jandot

11/12/2007 5:26:00 PM

0

On 12 Nov, 17:02, furtive.cl...@gmail.com wrote:
> Bio = Module.new
> Bio::Graphics = Module.new
> Bio::Graphics::Panel = Class.new
> Bio::Graphics::Panel::Track = Class.new
> Bio::Graphics::Panel::Track::Feature = Class.new
>
> class Bio::Graphics::Panel::Track::Feature
> def foo
> puts "foo"
> end
> end
>
> Bio::Graphics::Panel::Track::Feature.new.foo # => "foo"

Thanks. It looks like this does the trick.

jan.

furtive.clown

11/13/2007 7:15:00 AM

0

On Nov 12, 12:02 pm, furtive.cl...@gmail.com wrote:
> Bio = Module.new
> Bio::Graphics = Module.new
> Bio::Graphics::Panel = Class.new
> Bio::Graphics::Panel::Track = Class.new

I should clarify that I could have written

module Bio ; end
module Bio::Graphics ; end
class Bio::Graphics::Panel ; end
class Bio::Graphics::Panel::Track ; end

it's just that I found the former nicer to look at.

Gene Ward Smith

5/19/2008 9:51:00 AM

0

MikeRyder <nono@nospam.com> wrote in
news:p9i234dcvd90f26igngfsggffn8pj2q04j@4ax.com:

> "Now" is obviously a word and to the ego describes a sense of
the
> present. Both "eternity" and "now" are ego's concepts. And
what's
> wrong with that?

What's wrong with that is that it renders your original claim
nonsense:

'In addition, "eternity" is an ego concept. "Now" is simply
now.'