[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] Ruby Facets 0.6.2

Trans

3/21/2005 8:37:00 PM

A N N O U N C I N G

Ruby Facets, v0.6.2

Fantastic Atomic Core Extensions


ABSTRACT: Ruby Facets is a cornicopia of core extensions for the Ruby
programming language. It is unique by virtue of the atomicity of its
design. Methods are stored in their own files, allowing for extremely
granular control of requirements. Ruby Facets is a subproject of Ruby
Calibre.


For More Information
http://calibre.rub...



ALL YOUR BASE ARE BELONG TO RUBY!


------------------------------------------------------------------------
(from ANN)

A new version of Ruby Facets is out: 0.6.2. This version adds some new
methods including the Kilmer inspired time and byte methods found in
Rails. Here's a brief list of additions/changes:

* Added kernel/resc as a shortcut for Regexp.escape.

* Renamed hash/keys_to_string to hash/key_to_s and hash/keys_to_symbol
to hash/keys_to_sym to be more consistant with other methods and what
these methods specifically do. The old names have been deprecated.

* Added hash/has_keys?, which allows for checking mutliple keys at once.
Also includes #has_only_keys?

* Added Rail's Time and Byte modules for Numeric with numeric/times.rb
and numeric/bytes.rb (I've been informed that thanks go to Rich Kilmer
for this. Thanks!)

* Added numeric/octet_unit which utilizes numeric/bytes. (The name of
this method may change in the future though.)

* Added enumerable/uniq_by.

* Added module/abstract.

* Added module/redirect which is similar to alias, but does not copy the
method, but rather wraps it. It also takes a hash so multiple methods
can be redirected all at once.

* Added string/shatter which is similar to split but includes the
matched portions of text.

If you are interested in contributing to a project but have little time
to spare, helping with Facets may be a perfect project. There are still
plenty of light-weight tasks to do: improve documentation, improve the
tests and write a few yet missing, improve the rohbustness of methods
themselves, including exceptional error catching, and of course there's
plenty of room for adding new goodies, too. If you have any extension
methods that you use and think may be of benefit to others, please let
me know.

And, of course, please let me know if you come across any bugs.

You can contact me either privately or via ruby-talk, or through the new
calibre-cuts mailing-list:

http://rubyforge.org/mailman/listinfo/ca...

Thanks,
T.


------------------------------------------------------------------------
Generated by PackMule, a dedicated Ruby Packaging Assistant.
Do you Ruby? (http://www.rub...)


13 Answers

Francis Hwang

3/21/2005 11:25:00 PM

0

Hi Trans,

On Mar 21, 2005, at 3:37 PM, TRANS wrote:
> * Added Rail's Time and Byte modules for Numeric with numeric/times.rb
> and numeric/bytes.rb (I've been informed that thanks go to Rich Kilmer
> for this. Thanks!)

Where would I find docs on this part of Facets? I looked at
http://calibre.rubyforge.org/facets/doc/... but didn't see
anything under Numeric there.

Francis Hwang
http://f...



Florian Gross

3/22/2005 12:54:00 AM

0

TRANS wrote:

> A new version of Ruby Facets is out: 0.6.2. This version adds some new
> methods including the Kilmer inspired time and byte methods found in
> Rails. Here's a brief list of additions/changes:

Perhaps it would also be a nice idea to add Enumerable#count,
Kernel#with and Object.new with a template block?

Samples:

[1, 2, 3].count { |item| item > 1 } # => 2
with("foo") { reverse } # "oof"

obj = Object.new("foo") { def reverse() "bar" end }
obj # => "foo"
obj.reverse # => "bar"

Daniel Amelang

3/22/2005 1:38:00 AM

0

> with("foo") { reverse } # "oof"

Perhaps I'm confused with your example because it's contrived (on
purpose, I know), but the above makes little sense. It's just a long
way of saying 'foo.reverse'. Or did you mean to use 'reverse!'

This is the way I understood how 'with' would work:

s = "hello"
with(s) {
reverse!
capitalize!
}
p s # Olleh

I'm actually not a big fan of the 'with' idea, or the Object.new {}
one, but I really like 'count'. Could have used it several times the
past couple months.

Dan


Trans

3/22/2005 4:31:00 AM

0

Ah, I hadn't removed the :nodoc: marker, so they didn't show up. Thanks
for pointing that out. It's fixed now, although those particular
methods aren't _fully_ documented yet. I'll do so for the next
release.

Thanks again,
T.

Trans

3/22/2005 4:35:00 AM

0

Florian Gross wrote:
> Perhaps it would also be a nice idea to add Enumerable#count,
> Kernel#with and Object.new with a template block?
>
> Samples:
>
> [1, 2, 3].count { |item| item > 1 } # => 2
> with("foo") { reverse } # "oof"
>
> obj = Object.new("foo") { def reverse() "bar" end }
> obj # => "foo"
> obj.reverse # => "bar"

Thanks for the suggestions. I'll have a look and give them a try in the
next release.

T.

Trans

3/22/2005 4:44:00 AM

0

> Perhaps it would also be a nice idea to add Enumerable#count,
> Kernel#with and Object.new with a template block?

Thanks. I will give them consideration for the next release.

T.

Martin DeMello

3/22/2005 7:00:00 AM

0

Florian Gross <flgr@ccan.de> wrote:
> TRANS wrote:
>
> > A new version of Ruby Facets is out: 0.6.2. This version adds some new
> > methods including the Kilmer inspired time and byte methods found in
> > Rails. Here's a brief list of additions/changes:
>
> Perhaps it would also be a nice idea to add Enumerable#count,
> Kernel#with and Object.new with a template block?

Object#apply is perhaps more rubyish-looking than Kernel#with(object)

martin

Florian Gross

3/22/2005 1:03:00 PM

0

Daniel Amelang wrote:

>>with("foo") { reverse } # "oof"
>
> Perhaps I'm confused with your example because it's contrived (on
> purpose, I know), but the above makes little sense. It's just a long
> way of saying 'foo.reverse'. Or did you mean to use 'reverse!'
>
> This is the way I understood how 'with' would work:
>
> s = "hello"
> with(s) {
> reverse!
> capitalize!
> }
> p s # Olleh
>
> I'm actually not a big fan of the 'with' idea, or the Object.new {}
> one, but I really like 'count'. Could have used it several times the
> past couple months.

I decided to return the last value of the block as that works in both
cases. Just add a self:

with(s) {
reverse!
capitalize!
self
}

Francis Hwang

3/23/2005 7:40:00 PM

0

Thanks for that. Can I humbly suggest that Numeric#ago be changed to
Numeric#before? If we're trying to mimic English, you'd never say "10
days ago yesterday" in English, but you would say "10 days before
yesterday". So instead of making people call

10.days.ago( Time.now - 1.day )

they could call

10.days.before( Time.now - 1.day )

instead. And if Time.yesterday and Time.tomorrow had been defined, you
could simply call

10.days.before Time.yesterday

And maybe this would cause transitional issues, but it might be good to
redefine Numeric#ago to refer to a time relative to the current moment,
which is in line with what it means in English.

yesterday = 1.day.ago
last_monday = 8.days.ago

Similarly, Numeric#later could go the other way:

tomorrow = 1.day.later
next_tuesday = 6.days.later

And Numeric#after could add time to any arbitrary starting point:

three_days_later = 2.days.after Time.tomorrow

I'd submit patches for these, but they're all pretty easy.





On Mar 21, 2005, at 11:34 PM, Trans wrote:

> Ah, I hadn't removed the :nodoc: marker, so they didn't show up. Thanks
> for pointing that out. It's fixed now, although those particular
> methods aren't _fully_ documented yet. I'll do so for the next
> release.
>
> Thanks again,
> T.
>
>
>

Francis Hwang
http://f...



Trans

3/23/2005 9:55:00 PM

0

Francis, great ideas! I will work on. Thank you.

BTW, I found it curious that these methods are so popular as they seem
contrary to OOP. Wouldn't an actual Byte class be more appropriate, for
instance?

T.