[ANN] Ruby/Extensions 0.2.0

G

Gavin Sinclair

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.rubyforge.org/rdoc.

Cheers,
Gavin
 
F

Florian Gross

Gavin said:
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
 
G

Gavin Sinclair

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
 
H

Hal Fulton

Gavin said:
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
 
G

Gavin Sinclair

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top