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.
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:
------------------------------------------------------------------------
Generated by PackMule, a dedicated Ruby Packaging Assistant.
Do you Ruby? (http://www.ruby-lang.org)
* 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!)
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?
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.
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.
Object#apply is perhaps more rubyish-looking than Kernel#with(object)
martin
···
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?
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:
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.
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.
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
···
On Mar 23, 2005, at 4:59 PM, Trans wrote:
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?
> 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.