[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 0.2.0

Gavin Sinclair

10/4/2003 12:39:00 PM

Hi -talk,

I have released Ruby (Standard Class) Extensions version 0.2.0. It
contains the following methods:

Class#autoinit
Enumerable#build_hash
Enumerable#collect_with_index
Enumerable#contains?
Enumerable#has?
Enumerable#includes?
Enumerable#map_with_index
IO::write
Integer#even?
Integer#odd?
Numeric#format_s
Object#in?
Object#singleton_class
String#ends_with?
String#expand_tabs
String#indent
String#outdent
String#starts_with?
String#taballto
String#tabto
String#trim

Full documentation is included and can be viewed at
http://extensions.rubyforg....

Cheers,
Gavin


4 Answers

Florian Gross

10/4/2003 4:41:00 PM

0

Gavin Sinclair wrote:
> Hi -talk,

Moin!

> I have released Ruby (Standard Class) Extensions version 0.2.0.

Could you include this in the next release? :)

class Symbol
def to_proc
proc { |obj, *args| obj.send(self, *args) }
end
end

It allows you do the following:

(1..10).inject(&:*) # => 3628800
%w{foo bar qux}.map(&:reverse) # => %w{oof rab xuq}
[1, 2, nil, 3, nil].reject(&:nil?) # => [1, 2, 3]
%w{ruby and world}.sort_by(&:reverse) # => %w{world and ruby}

> Cheers,
> Gavin

Regards,
Florian Gross


Gavin Sinclair

10/5/2003 12:36:00 AM

0

On Sunday, October 5, 2003, 2:41:25 AM, Florian wrote:

> Gavin Sinclair wrote:
>> Hi -talk,

> Moin!

>> I have released Ruby (Standard Class) Extensions version 0.2.0.

> Could you include this in the next release? :)

> class Symbol
> def to_proc
> proc { |obj, *args| obj.send(self, *args) }
> end
> end

> It allows you do the following:

> (1..10).inject(&:*) # => 3628800
> %w{foo bar qux}.map(&:reverse) # => %w{oof rab xuq}
> [1, 2, nil, 3, nil].reject(&:nil?) # => [1, 2, 3]
> %w{ruby and world}.sort_by(&:reverse) # => %w{world and ruby}


That's quite nice. Are there any nasty side-effects? I suppose not,
since you must inform Ruby that you intend to use a symbol in place of
a proc with the '&'. I'll chuck it in now, but it won't see a release
for a while.

Thanks,
Gavin


Hal E. Fulton

10/5/2003 1:39:00 AM

0

Gavin Sinclair wrote:
> On Sunday, October 5, 2003, 2:41:25 AM, Florian wrote:
>>Could you include this in the next release? :)
>
>
>>class Symbol
>> def to_proc
>> proc { |obj, *args| obj.send(self, *args) }
>> end
>>end
>
>
>>It allows you do the following:
>
>
>>(1..10).inject(&:*) # => 3628800
>>%w{foo bar qux}.map(&:reverse) # => %w{oof rab xuq}
>>[1, 2, nil, 3, nil].reject(&:nil?) # => [1, 2, 3]
>>%w{ruby and world}.sort_by(&:reverse) # => %w{world and ruby}
>
> That's quite nice. Are there any nasty side-effects? I suppose not,
> since you must inform Ruby that you intend to use a symbol in place of
> a proc with the '&'. I'll chuck it in now, but it won't see a release
> for a while.

I like that, but I am already used to the "mapf" that someone proposed
long ago ("map function").

It's less general but it's also less magic and takes one less
punctuation mark (though one more letter).

%w[foo bar bam].mapf(:reverse)

I'd vote for inclusion of that one also.

Hal



Gavin Sinclair

10/5/2003 5:04:00 AM

0

On Sunday, October 5, 2003, 11:39:15 AM, Hal wrote:

>> [...]

> I like that, but I am already used to the "mapf" that someone proposed
> long ago ("map function").

> It's less general but it's also less magic and takes one less
> punctuation mark (though one more letter).

> %w[foo bar bam].mapf(:reverse)

> I'd vote for inclusion of that one also.


Yes, I like mapf; in fact I asked for it on this list many moons ago.
On the one hand, it's an annoying specialisation of what
Symbol#to_proc allows. On the other hand, it's funky. And #map is a
very commonly used method, and it's used commonly with very simple
blocks, so it has special consideration.

It's in the CVS.

Gavin