[ANN] Ruby Facets 0.6.2

T

TRANS

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



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/calibre-cuts

Thanks,
T.
 
F

Florian Gross

TRANS said:
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"
 
D

Daniel Amelang

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
 
T

Trans

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.
 
T

Trans

Florian said:
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.
 
T

Trans

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.
 
M

Martin DeMello

Florian Gross said:
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
 
F

Florian Gross

Daniel said:
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
}
 
F

Francis Hwang

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.





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://fhwang.net/
 
T

Trans

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.
 
F

Francis Hwang

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?

Definitely, but I suppose this is generally a problem with OO
hierarchies: They work better on the edges, at specific classes, than
in the center, at general-purpose classes. Numeric might be the most
amenable to this, what with mathematics being a general-purpose way to
abstract many other domains--whether you're dealing with a calendar or
a computer's addressing space.

They're definitely hacks, but that's okay! When it comes down to it,
it's all about syntactic sugar anyway--even OO itself. OO is the
sweetest syntactic sugar I know.

Francis Hwang
http://fhwang.net/
 
T

Trans

Francis said:
Definitely, but I suppose this is generally a problem with OO
hierarchies: They work better on the edges, at specific classes, than
in the center, at general-purpose classes. Numeric might be the most
amenable to this, what with mathematics being a general-purpose way to
abstract many other domains--whether you're dealing with a calendar or
a computer's addressing space.

They're definitely hacks, but that's okay! When it comes down to it,
it's all about syntactic sugar anyway--even OO itself. OO is the
sweetest syntactic sugar I know.

I like your explination :)

T.
 
T

Trans

Francis said:
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.

All done. And no transistional issues to speak-of. Expect them with the
next release (Probably a few weeks from now).

T.
 

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

[ANN] Ruby Facets, v0.6.1 0
[ANN] Ruby Facets 0.6.3 0
[ANN] Ruby Facets, v0.6.0 0
[ANN] Ruby Facets 0.7.2 0
[ANN] Facets 1.8 4
[ANN] ri_cal 0.6.2 Released 0
[ANN] Facets 2005-10-30 9
[ANN] NotNaughty 0.6.2 0

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,747
Members
45,545
Latest member
rapter____0

Latest Threads

Top