[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] Ruby/Extensions v0.6.0

Gavin Sinclair

12/8/2004 2:12:00 PM

I am pleased to announce the release of v0.6.0 of Ruby/Extensions
('extensions').

== What Is It?

A set of methods added to Ruby's standard classes. A few examples,
taken from the methods added in this release:

arr = [1, 3, 5]
arr.rand # -> 1, 3, or 5
arr.none? { |n| n.even? } # -> true
arr.one? { |n| n > 4 } # -> true

Class.by_name "Process::Sys" # -> Process::Sys
Process::Sys.basename # -> "Sys"

'extensions' now contains 52 methods spread around 12 of Ruby's
classes, all well tested and documented.

== Links

http://extensions.ruby... (read about it)
http://rubyforge.org/frs/?g... (download it)

== Installation

gem install extensions

(RPA support usually lags only 1 day.)

Or grab the tarball.

Cheers,
Gavin



9 Answers

Florian Gross

12/8/2004 2:18:00 PM

0

Gavin Sinclair wrote:

> I am pleased to announce the release of v0.6.0 of Ruby/Extensions
> ('extensions').

Same question as with RubyScript2Exe here: What was added and changed?
Is a change log available? Thank you.

Gavin Sinclair

12/8/2004 2:32:00 PM

0

On Thursday, December 9, 2004, 1:22:29 AM, Florian wrote:

> Gavin Sinclair wrote:

>> I am pleased to announce the release of v0.6.0 of Ruby/Extensions
>> ('extensions').

> Same question as with RubyScript2Exe here: What was added and changed?
> Is a change log available? Thank you.

A change log is included in the rubyforge release:

2004-12-09 Gavin Sinclair <gsinclair@soyabean.com.au>

* RELEASE: 0.6.0 ===================================================
* lib/extensions/array.rb: Implemented Array#only and #rand.
* test/tc_array.rb: Test Array#only and #rand.
* lib/extensions/module.rb: [NEW] Implemented Module.by_name,
Module#basename, and Module#deep_const_get.
* test/tc_module.rb: [NEW] Test the aforementioned Module methods.
* lib/extensions/enumerable.rb: Implemented Enumerable#none? and #one?
* test/tc_enumerable.rb: Test aforementioned Enumerable methods.
* lib/extensions/kernel.rb: Implemented Kernel#relative_require.
* test/tc_kernel.rb: Test Kernel#relative_require.
* lib/extensions/numeric.rb: Added comment for possible future method.
* lib/extensions/all.rb: Included new files module.rb and kernel.rb.
* test/data/kernel_test/global_var_1.rb: [NEW] test data file.
* test/data/kernel_test/global_var_2.rb: [NEW] test data file.
* README: Updated to describe release of 0.6.

The methods added since 0.5 are summarised on the website:

+ Array#only
+ Array#rand
+ Enumerable#none?
+ Enumerable#one?
+ Kernel#require_relative
+ Module.by_name
+ Module#basename
+ Module#deep_const_get

In future releases, I'll change the ChangeLog to an RDoc-friendly
format and publish it on the website.

Cheers,
Gavin



Mauricio Fernández

12/8/2004 3:16:00 PM

0

On Wed, Dec 08, 2004 at 11:12:29PM +0900, Gavin Sinclair wrote:
> I am pleased to announce the release of v0.6.0 of Ruby/Extensions
> ('extensions').
[...]
> (RPA support usually lags only 1 day.)

Not always: in some cases the packaging task is pretty involved and can
take longer (when there are complex dependencies, lots of glitches in
the upstream release to be fixed, etc). In this case it was easy, and we
have to thank you for following (maybe unknowingly) most of the practices
explained at
http://rpa-base.rubyforge.org/wiki/wiki.cgi?Goo...

Also, http://rpa-base.rubyforge.org/wiki/wiki.cgi?Goo... might
interest you.

> Or grab the tarball.

I noticed that the permissions in the tarball seem wrong (too many files
are 755), maybe that can be addressed in the next release.


Port: extensions
Classification: Top.Library.Development
Available-Version: 0.6.0-1
RPA-Version: 0.0
Updated: Wed, 08 Dec 2004 15:52:53 +0100
Source-URL: http://rpa-base.rubyforge.org/ports/extensions_0...
Description:
Extensions to the Ruby standard classes.
.
This project contains several extensions to the Ruby standard classes. Many
are sourced from the Ruby Wiki.
.
Criteria for inclusion of a method are:
- the method serves a general purpose
- it is reasonably clear from the method name what its behaviour is
- it would not generally be out of place in the language itself
.
Apart from convenience, the benefit of this package is to provide a
reference.
You can use this package for your convenience, and deploy your code with a
clear dependency on it, since anyone can download it. That is better than
releasing your package with a few ad hoc standard class modifications, and
hoping that they don't conflict with any code your users have written.
.
Long story short: it's useful that Ruby allows you to add methods to existing
classes, even built-ins like String and Array. Some people rightfully are
uneasy about actually doing so, because of possible conflicts. This project
offers a standard set of extensions in order to mitigate that uneasiness by
making them publicly available, and well documented.


--
Hassle-free packages for Ruby?
RPA is available from http://www.rubyar...


Gavin Sinclair

12/8/2004 3:40:00 PM

0

On Thursday, December 9, 2004, 2:16:10 AM, Mauricio wrote:

> On Wed, Dec 08, 2004 at 11:12:29PM +0900, Gavin Sinclair wrote:
>> I am pleased to announce the release of v0.6.0 of Ruby/Extensions
>> ('extensions').
> [...]
>> (RPA support usually lags only 1 day.)

> Not always: in some cases the packaging task is pretty involved and can
> take longer (when there are complex dependencies, lots of glitches in
> the upstream release to be fixed, etc). In this case it was easy, and we
> have to thank you for following (maybe unknowingly) most of the practices
> explained at
> http://rpa-base.rubyforge.org/wiki/wiki.cgi?Goo...

I meant that RPA support for 'extensions' usually lags only one day,
precisely because I try to follow most of the practices explained at

http://rpa-base.rubyforge.org/wiki/wiki.cgi?Goo...

:)

>> Or grab the tarball.

> I noticed that the permissions in the tarball seem wrong (too many files
> are 755), maybe that can be addressed in the next release.

Thanks, I'll try to fix that.

Gavin



Aredridel

12/8/2004 6:41:00 PM

0

On Thu, 9 Dec 2004 00:39:40 +0900, Gavin Sinclair
<gsinclair@soyabean.com.au> wrote:
> I meant that RPA support for 'extensions' usually lags only one day,
> precisely because I try to follow most of the practices explained at
>
> http://rpa-base.rubyforge.org/wiki/wiki.cgi?Goo...

And thank you for that. It took me eight minutes to package up the new
version for PLD's repository, and seven and a half minutes of that
were me figuring out that I used the wrong download URL and got bit by
GForge's bug that lets you download an old file with a new name
instead of getting a 404.

A quality release!


Florian Gross

12/8/2004 7:53:00 PM

0

Gavin Sinclair wrote:

> The methods added since 0.5 are summarised on the website:
>
> + Array#only
> + Array#rand
> + Enumerable#none?
> + Enumerable#one?
> + Kernel#require_relative
> + Module.by_name
> + Module#basename
> + Module#deep_const_get

Thanks, I was fearing that there would be name clashes with the
Ruby-Junction library which defines Enumerable#none, #any, #all,
#with_count and #exactly.

Array#rand sounds interesting, but I wonder if it does not lead to
trouble when using rand() from a custom overloaded Array or Enumerable
method.

Gavin Sinclair

12/9/2004 12:05:00 AM

0

On Thursday, December 9, 2004, 6:57:28 AM, Florian wrote:

>> The methods added since 0.5 are summarised on the website:
>> [...]

> Thanks, I was fearing that there would be name clashes with the
> Ruby-Junction library which defines Enumerable#none, #any, #all,
> #with_count and #exactly.

You might be interested to know that 'extensions' is careful about
adding methods. If, for example, you did this:

class Array; def rand; ...; end; end

require 'extensions/array'

then you'd get a warning on STDERR, something like

WARNING: Array#rand exists, not overwriting

But obviously method clashes are better discovered by human
communication than by code. I'll have to check out the Ruby-Junction
library.

> Array#rand sounds interesting, but I wonder if it does not lead to
> trouble when using rand() from a custom overloaded Array or Enumerable
> method.

What might an example of this trouble be? For a start, it's only
defined on Array, not Enumerable. And its definition is very simple:

def rand
idx = Kernel.rand(self.size)
at(idx)
end

So any array that properly implements size and at should do the trick.

BTW Florian, while I've got you on this subject, I must apologise for
an incorrect attribution in extensions: Florian Frank appears in there
on one occasion instead of you. FINR :)

Cheers,
Gavin




Florian Gross

12/9/2004 12:28:00 AM

0

Gavin Sinclair wrote:

> On Thursday, December 9, 2004, 6:57:28 AM, Florian wrote:
>>Thanks, I was fearing that there would be name clashes with the
>>Ruby-Junction library which defines Enumerable#none, #any, #all,
>>#with_count and #exactly.
> You might be interested to know that 'extensions' is careful about
> adding methods. If, for example, you did this:
>
> class Array; def rand; ...; end; end
>
> require 'extensions/array'
>
> then you'd get a warning on STDERR, something like
>
> WARNING: Array#rand exists, not overwriting

Oh, that's quite a nifty feature. Well done!

>>Array#rand sounds interesting, but I wonder if it does not lead to
>>trouble when using rand() from a custom overloaded Array or Enumerable
>>method.
> What might an example of this trouble be? For a start, it's only
> defined on Array, not Enumerable. And its definition is very simple:
>
> def rand
> idx = Kernel.rand(self.size)
> at(idx)
> end
>
> So any array that properly implements size and at should do the trick.

I'm thinking about something like this: (Made-up sample, does not make
much sense in isolation -- but it could also happen in real code.)

class Enumerable
def find_some(chance = 0.5)
find_all { rand < chance }
end
end

I think using the Array#rand extension would lead to trouble in this case:

[1, 2, 3].find_some

Because Enumerable#find_some expects to call Kernel#rand.

I'm not sure if it is necessary to rename it (Array#pick_rand seems to
be a common candidate), but a note in the documentation might be a good
thing.

> BTW Florian, while I've got you on this subject, I must apologise for
> an incorrect attribution in extensions: Florian Frank appears in there
> on one occasion instead of you. FINR :)

Oh, no problem there -- we tend to get confused a lot. I guess one could
refer to me as 'flgr' instead in case it would help.

Gavin Sinclair

12/9/2004 12:51:00 AM

0

On Thursday, December 9, 2004, 11:32:31 AM, Florian wrote:

>> So any array that properly implements size and at should do the trick.

> I'm thinking about something like this: (Made-up sample, does not make
> much sense in isolation -- but it could also happen in real code.)

> class Enumerable
> def find_some(chance = 0.5)
> find_all { rand < chance }
> end
> end

> I think using the Array#rand extension would lead to trouble in this case:

> [1, 2, 3].find_some

> Because Enumerable#find_some expects to call Kernel#rand.

OIC. Yes, when dabbling in these waters I tend to be explicit, so I
would use Kernel.rand instead.

> I'm not sure if it is necessary to rename it (Array#pick_rand seems to
> be a common candidate), but a note in the documentation might be a good
> thing.

Yes. I'll put something in.

Gavin