[ANN] Ruby/Extensions v0.3 released

G

Gavin Sinclair

A new version of Ruby/Extensions, a suite of useful methods added to
Ruby's built-in classes, has been released. Version 0.3 consolidates 8
new or improved methods since version 0.2.

See http://extensions.rubyforge.org for details. A complete list of
methods implemented is listed below.

Class#autoinit
Enumerable#build_hash
Enumerable#collect_with_index
+ Enumerable#collectf
Enumerable#contains?
Enumerable#has?
Enumerable#includes?
Enumerable#map_with_index
+ Enumerable#mapf
+ Enumerable#partition_by
IO::write
Integer#even?
Integer#odd?
* Numeric#format_s
Object#in?
+ Object#pp_s
Object#singleton_class
+ String#cmp
String#ends_with?
String#expand_tabs
String#indent
String#leftmost_indent
+ String#line
String#outdent
String#starts_with?
String#taballto
String#tabto
String#trim
+ Symbol#to_proc

(+ indicates new method since 0.2; * indicates improved method since 0.2)

Cheers,
Gavin
 
H

Hal Fulton

Gavin said:
A new version of Ruby/Extensions, a suite of useful methods added to
Ruby's built-in classes, has been released. Version 0.3 consolidates 8
new or improved methods since version 0.2.

Gavin,

I like this project and I hope to add to it from time to time.

The other day I was having trouble thinking of the name of the project,
however. I think this is because I associate the term "extension" in
Rubyland with C extensions, whereas this is a pure-Ruby project (is it
not?).

Do you think the confusion would be great enough to justify changing
the name? Just a thought. Your project, not mine.


Cheers,
Hal
 
T

T. Onoma

A new version of Ruby/Extensions, a suite of useful methods added to
Ruby's built-in classes, has been released. Version 0.3 consolidates 8
new or improved methods since version 0.2.

See http://extensions.rubyforge.org for details. A complete list of
methods implemented is listed below.

hi Gavin,

first let me say that i think this is a very admirable project. it provides
some stadardization to standard class methods that are not quite common
enough to be included in ruby proper, as well as "trial arena" for possible
inclusion into ruby proper in the future.

i am wondering, given the stated goals, in what direction you plan to proceed
as submissions are made to the project? will you further modularize the
extensions or will you instead limit what can be a part of these extensions?
for instance, in my programs i sometimes include my own modifications to ruby
core classes, one of the main changes consits of some method additions to
NilClass.

class NilClass
def to_f; 0.0; end
def to_h; {}; end
def empty?; true; end
alias size to_i
alias length to_i
end

how might this fit in with the project?

thanks,
T.
 
G

Gavin Sinclair

i am wondering, given the stated goals, in what direction you plan to proceed
as submissions are made to the project? will you further modularize the
extensions or will you instead limit what can be a part of these extensions?
for instance, in my programs i sometimes include my own modifications to ruby
core classes, one of the main changes consits of some method additions to
NilClass.
class NilClass
def to_f; 0.0; end
def to_h; {}; end
def empty?; true; end
alias size to_i
alias length to_i
end
how might this fit in with the project?


Those methods make sense only in very specific cases. They assume you
want +nil+ to be like a valid string, integer, array, etc. That's an
assumption I (almost) never want to make in my code.

One of the stated goals of the project is that methods be general
purpose. That's a pretty vague aim, but it's pretty clear that the
methods above are not general purpose.

Cheers,
Gavin
 
G

Gavin Sinclair

I like this project and I hope to add to it from time to time.
The other day I was having trouble thinking of the name of the project,
however. I think this is because I associate the term "extension" in
Rubyland with C extensions, whereas this is a pure-Ruby project (is it
not?).
Do you think the confusion would be great enough to justify changing
the name? Just a thought. Your project, not mine.


Such confusion has certainly occurred to me. The project is
sort-of-called "Ruby/Extensions" but of course the RubyForge "unix"
name is "extensions", which is a bit too general perhaps.

But I've never thought of anything better. Feel free to suggest.

Cheers,
Gavin
 
T

T. Onoma

Those methods make sense only in very specific cases. They assume you
want +nil+ to be like a valid string, integer, array, etc. That's an
assumption I (almost) never want to make in my code.

do you think NilClass' to_a and to_i methods should be removed then?
One of the stated goals of the project is that methods be general
purpose. That's a pretty vague aim, but it's pretty clear that the
methods above are not general purpose.

hmm... to me they seem even more general purpose then most, since they are so
very basic. the differnce is whether one views the NilClass as a
representation of "emptiness" vs. "notness" (for lack of better words). my
additional methods thus adding in the way on the point of view of
"emptiness". in my experience (and honestly a bit to my suprise) i have never
run into any difficulties by including these methods and putting to use these
two different conceptions of nil; though sometimes i do think it might be
nice to separate the "notness" out into a separate NackClass, all the same.

anyway, i think you've answered my question. Ruby/Extensions is intended as a
restricted set of approved inclusions rather than an open collection of
acceptable inclusions. that's fine. i just wanted to be clear on the goals of
the project.

thanks gavin,
T.
 
A

Ara.T.Howard

Date: Sat, 24 Jan 2004 09:02:10 +0900
From: Gavin Sinclair <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Re: [ANN] Ruby/Extensions v0.3 released
But I've never thought of anything better. Feel free to suggest.
</snip>

require 'boost'

??

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
G

gabriele renzi

il Sat, 24 Jan 2004 09:02:10 +0900, Gavin Sinclair
But I've never thought of anything better. Feel free to suggest.


woowoo! playing the nbame game again :)

I'd suggest 'ext-for'
so you can do :

require 'ext-for/string'

:))
 
G

Gavin Kistner

Gavin said:
A new version of Ruby/Extensions, a suite of useful methods added to
Ruby's built-in classes, has been released. Version 0.3 consolidates 8
new or improved methods since version 0.2.

May I make the suggestion of adding in some convenience methods for the
Time class for manipulating dates, similar to what Javascript has?

http://phrogz.net/ObjJob/object.asp?id=224
shows the full list of methods, and in particular I'm thinking of
methods that allow you to set the date (day number) without having to
muck about with seconds.

For example, the following JS code is quite common for figuring a day at
some point in the future:

var nextWeek = new Date();
nextWeek.setDate(nextWeek.getDate()+7);
//JS internally modifies the number of milliseconds,
//so if the day number is 'invalid', it actually wraps
//to the next month.

In Ruby this could be like:
nextWeek = Time.new
nextWeek.date+=7;


If you'd like me (novice developer) to take a stab at an initial
implementation of these, I'd be happy to.
 
G

Gavin Kistner

Gavin said:
May I make the suggestion of adding in some convenience methods for the
Time class for manipulating dates, similar to what Javascript has?

OK, so for some reason I totally missed the Date class in the standard
library. I think I'll take a long look at it before attempting to renew
this suggestion :)
 
F

Florian Gross

Gavin said:
May I make the suggestion of adding in some convenience methods for the
Time class for manipulating dates, similar to what Javascript has?

I think Time#year, #month, #week and #day could be useful. (#hour and
#minute seem to be a bit extreme, but they might still be added.)

What about adding these: (taken from good_time.rb ;))

# This makes Time act more like the Enumerable it really is
# It also adds some Time travel methods

class Time
class Slice < Array; end

extend Enumerable

def succ
self + 1
end

def upto(other)
self.to_i.upto(other.to_i) { |item| yield Time[item] }
end

def downto(other)
self.to_i.downto(other.to_i) { |item| yield Time[item] }
end

class << self
def [](*args)
args = args.first .. (args.first + args.last) if args.length == 2
index = args.first
unless index.is_a? Range
at(index)
else
index.inject(Time::Slice.new) {|state, item| state << at(item)}
end
end

def first; self[0]; end
def last; self[2**31-1]; end

def each
first.upto(last) { |item| yield item }
end

alias :eek:ld_now :now
def now;
at(old_now.to_i + (@offset || 0))
end

attr_accessor :eek:ffset

def set(to)
@offset ||= 0
@offset += to.to_i - Time.now.to_i
now
end

alias :goto :set
alias :travel :set
def rewind; goto(Time.first); end

# optimizations
def max; last; end
def min; first; end
def include?(item); (first..last).include? item; end
alias :member? :include?
end
end
 
G

Gavin Sinclair

Date: Sat, 24 Jan 2004 09:02:10 +0900
From: Gavin Sinclair <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Re: [ANN] Ruby/Extensions v0.3 released
But I've never thought of anything better. Feel free to suggest. </snip>

boost
toolbox
enhance
extras
standard class extensions -> sce

I like requiring 'toolbox' :)

Yes, nice one. That doesn't capture the essense of the project,
though, which is strictly extensions to built-in classes. "Toolbox"
sounds more general.

Perhaps 'sce'. Not pretty, but definitive. But D'OH! RubyForge
insists on 4-letter names :)

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top