yves piel
3/1/2005 1:01:00 PM
Robert Klemme wrote:
> "yves piel" <yvespielusenet@free.fr> schrieb im Newsbeitrag
> news:422444a1$0$3187$636a15ce@news.free.fr...
>
>>Hello,
>>I'm a java developper and I want to test Ruby which seems a very
>>powerfull/easy language :)
>>I read doc about how to program but I never see something telling me how
>> to structure a programme...
>>So in Java there are "packages" witch contains "classes" and when I
>>launch Java I tell it where are those package so I can access to
>
> classes.
>
>>Is there something similar in Ruby ?
>
>
> In Ruby it's called "Module":
>
> module Foo
> class Bar
> end
> end
>
> x = Foo::Bar.new
> x = ::Foo::Bar.new
>
>
>>Where can I stock classes than I
>>wrote ? Must I store them into the same directory (I don't think so...)
>
> ?
>
> You can do that (for example for small projects). You can even define
> them in a single file.
>
> If you have a more complex application, the usual approach is to put stuff
> into a module and have a file with a similar name:
>
> file foo.rb:
>
> require 'foo/bar'
> require 'foo/other'
> module Foo
> end
>
> file foo/bar.rb:
>
> module Foo
> module Bar
> class Y
> end
> end
> end
>
> You can also look at the std lib for examples.
>
>
>>thank for your help :)
>
>
> Kind regards
>
> robert
>
ok, thank you :)
So I can say that the Bar module is a 'subpackage' of the Foo one.
If in the Bar Module I want to have more class, I can create a file :
file: foo/barExt.rb
module Foo
module Bar
class X<Y
end
end
end
Is that right ?
So there are "modules" into modules there are "classes" and "functions"
into classes there are "functions" and "attributes"
:)