Giter VIP home page Giter VIP logo

facets's Introduction

Ruby Facets

Gem Version Build Status     Flattr Me

"ALL YOUR BASE ARE BELONG TO RUBY"

Introduction

Ruby Facets is the premiere collection of general purpose method extensions and standard additions for the Ruby programming language.

Facets houses the largest single collection of methods available for extending the core capabilities of Ruby's built-in classes and modules. This collection of extension methods are unique by virtue of their atomicity. The methods are stored in individual files so that each can be required independently. This gives developers the potential for much finer control over which extra methods to bring into their code.

In addition Facets provides a collection of extensions to Ruby standard library plus a small collection of add-on classes and modules. Together these libraries constitute an reliable source of reusable components, suitable to a wide variety of usecases.

Resources

Documentation

Facets has special documentation needs due to its extensive breadth. The documentation generated when installing via RubyGems, or the YARD docs provided by rubydoc.info can be somewhat unwieldy because it combines all of Facets in one large set. When using these resources, it is important to remain aware of the source location of particular methods.

For better organized online documentation, generated to separate core extensions from standard libraries, see the Learn Facets page on the website for links to available documentation.

Installation

Bundler

If you are using Bundler with your project, add the facets gem to the project's Gemfile. Unless you want all of facets loaded be sure to add the :require => false option.

gem "facets", require: false

RubyGems

The easiest way to install is via RubyGems.

$ gem install facets

Setup.rb

Facets can be installed the old-fashioned way using Setup.rb. Download and unpack the .tar.gz package and run setup.rb, like so:

$ tar -xvzf facets-2.x.x.tar.gz
$ cd facets-2.x.x
$ sudo setup.rb

Facets 2.8+ requires Ruby 1.8.7 or higher. Facets 3.0+ requires Ruby 2.0.0 or higher.

Mission

Facets holds to the notion that the more we can reasonably integrate into a common foundation, directed toward general needs, the better that foundation will be able to serve the community. There are a number of advantages here:

  • Better Code-reuse
  • Collaborative Improvements
  • Greater Name Consistency
  • One-stop Shop and Installation

Usage

CORE Library

At the heart of Ruby Facets is the CORE extensions library. CORE provides a sizable collection of generally useful methods, along with a few supporting classes, that extend the functionality of Ruby's core classes and modules.

With the exception of a few uncommon extensions, CORE contains anything that will load automatically when issuing:

require 'facets'

This loads all the CORE functionality at once. If you plan to use more then a handful of Facets core methods it is recommended that you require the library in this way. However, you can also "cherry pick" the CORE library as you prefer. And for uncommon extensions this must be done. The general require statement for a core extension library is:

require 'facets/<class|module>/<method>'

For example:

require 'facets/time/stamp'

Most "atoms" contain only one method, but exceptions occur when methods are closely tied together.

You can load per-class or per-module groups of core methods by requiring the class or module by name. For example"

require 'facets/time'

Will require all the core Time method extensions.

Note that some methods that were part of CORE in 1.8 and earlier are now part of MORE libraries. A good example is 'random.rb'. There were separated because they had more specialized use cases, where as CORE extensions are intended as general purpose.

Method File Names

Operator method redirect files are stored using English names. For instance Proc#* is proc/op_mul.

For reference, here is the chart.

 +@   => op_plus
 -@   => op_minus
 +    => op_add
 -    => op_sub
 **   => op_pow
 *    => op_mul
 /    => op_div
 %    => op_mod
 ~    => op_tilde
 <=>  => op_cmp
 <<   => op_lshift
 >>   => op_rshift
 <    => op_lt
 >    => op_gt
 ===  => op_case
 ==   => op_equal
 =~   => op_apply
 <=   => op_lt_eq
 >=   => op_gt_eq
 |    => op_or
 &    => op_and
 ^    => op_xor
 []=  => op_store
 []   => op_fetch

Facets simply takes the '*' and translates it into a string acceptable to all file systems. Also, if a method ends in '=', '?' or '!' it is simply removed.

MORE Library (aka Standard Library)

On top of the extensive CORE library, Facets provides extensions for Ruby's standard library, as well as a small collection of additional modules and classes to supplement it.

Use this library like you would any other 3rd party library. The only difference between Facet's Standard library and other libraries is the lack of any enclosing Facets:: namespace.

When using Facets extended versions of Ruby's standard libraries, the libraries have to loaded individually. However you do not need to load Ruby's library first, as the Facets' library will do that automatically.

For example, normally one load Ruby's OpenStruct class via:

require 'ostruct'

To load 'ostruct.rb' plus Facets extensions for it simply use:

require 'facets/ostruct'

For details pertaining to the functionality of each feature, please see the API documentation.

Contribute

This project thrives on contribution!

If you have any extension methods, classes or modules that you think have very general applicability and would like to see them included in this project, don't hesitate to submit. Also, if you have better versions of any thing already included or simply have a patch, they are more than welcome. We want Ruby Facets to be of the highest quality.

Development

Facets uses the Lemon testing framework to handle unit testing, while QED specifications provide tested documentation.

Facets uses Detroit and Rulebow build tools. Detroit is a life-cycle tool and Rulebow is a continuous integration tool. These tools, via the Assembly and Rulebook scripts respectively, sometimes use other tools such as Mast and Indexer. In addition we support Rake and Guard build tools, which most developers are familiar with. Note, that while these build tools can be easy circumvented, the Mast and Indexer tools are necessary to prepare Facets for release.

Authors

Much of this collection was written and/or inspired by a variety of great Ruby developers. Fortunately nearly all utilized works were copyrighted under the same open licenses, the Ruby License or the more liberal BSD and MIT licenses. In the one or two exceptions the copyright notice has been included with the source code. We have since received permission from the various authors to normalize the licensing to a single license. For this purpose we have chosen the BSD 2 Clause License. This is the license Ruby itself now uses, so it seemed the most appropriate choice. It is also almost identical to the MIT license. Any code file not specifically labeled otherwise shall fall under the this license (which is BSD 2-clause).

In all cases, every effort has been made to give credit where credit is due. You will find these acknowledgments embedded in the source code. You can see them in "CREDIT:" and/or "@author" lines. Also see the Contributors page on the Wiki for a list of all contributing Rubyists. If anyone is missing from the list, please let us know so we can correct. Thanks.

This collection was put together by, and much of it written by trans. If need be, he can be reached via email at transfire at gmail.com.

License

The collection PER COLLECTION is licensed as follows:

Ruby Facets
Copyright (c) 2005 Rubyworks

Distributed under the terms of the BSD-2 License (same as Ruby license).

The BSD 2 Clause License is a simple open source license. The complete text of the license accompany this document (see the enclosed LICENSE file).

Acknowledgments and Copyrights for particular snippets of borrowed code are given in their respective source. At this point, all licensing has been normalized for all included code. Original authors have given permission for inclusion of their code under such license, with appropriate credit citations.

"ALL YOUR BASE ARE BELONG TO RUBY!"

Ruby Facets, Copyright (c) 2005 Rubyworks

Do you Ruby? (http://ruby-lang.org)

facets's People

Contributors

aguynamedryan avatar andyt avatar anithri avatar benjamintanweihao avatar bitherder avatar ccjr avatar chocolateboy avatar cielavenir avatar codeindulgence avatar danbernier avatar emirikol avatar esparta avatar fd00 avatar ioquatix avatar ipagbox avatar jc00ke avatar jurisgalang avatar kb avatar kotp avatar lavirthewhiolet avatar leifcr avatar lucapette avatar lunks avatar msavy avatar smtlaissezfaire avatar sprachprofi avatar szuecs avatar tilo avatar trans avatar tylerrick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facets's Issues

Error when requiring "facets/random" after "facets"

irb(main):002:0> require 'facets'
/var/lib/gems/1.8/gems/facets-2.9.3/lib/core/facets/filetest/separator_pattern.rb:5: warning: already initialized constant SEPARATOR_PATTERN
/var/lib/gems/1.8/gems/facets-2.9.3/lib/core/facets/string/bracket.rb:3: warning: already initialized constant BRA2KET
=> true
irb(main):003:0> require 'facets/random'
SystemStackError: stack level too deep
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/core/facets/kernel/extend.rb:25:in `_extend'
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/core/facets/kernel/extend.rb:25:in `_extend'
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/core/facets/kernel/extend.rb:25:in `extend'
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/standard/facets/random.rb:338:in `included'
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/standard/facets/random.rb:442:in `include'
        from /var/lib/gems/1.8/gems/facets-2.9.3/lib/standard/facets/random.rb:442
        from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from (irb):3
        from (null):0

Problems with Enumerable#map_by

I use Enumerable#map_by a lot, it's a great abstraction because, more often than not, Enumerable#group_by falls too short. However, there are a couple of closely related problems with its implementation and specifications:

  1. Implementation: insufficient checks of the returned value of the block:
[[:a, true], [:b, false], [:c, nil]].map_by { |x, y| [x, y] }
#=> {:a=>[true], :b=>[[:b, false]], :c=>[[:c, nil]]}

Would'n you expect {:a=>[true], :b=>[false], :c=>[nil]}?

  1. Specifications: "if a second value is not returned, #map_by acts like #group_by.". The problem is that you cannot tell an array (which you may intent to use as a key) from a pair [key, value]. You may for example write:
[1, 2, 3].map_by { |x| [x, 2*x] }
#=> {1=>[2], 2=>[4], 3=>[6]}

But what you expected was {[1, 2]=>[1], [2, 4]=>[2], [3, 6=>[3]}. The old Unix adagio probably applies: "do one thing and do it well".


It looks to me that while (1) is easily solvable, (2) suggests that trying to act like group_by was a bad idea after all (if you wanted a group_by shouldn't you be using group_by anyway?). Granted, that change would break some old code (though I am not sure many people were actually using map_by that way...).

I can prepare a pull request with the conclusion of the conversation, I wanted to gather some opinions first.

Time and DateTime extensions

Time and DateTime extensions need the most work. This has been put off for some time thinking that Ruby would get it's shit together and improve the situation. But it doesn't look like it will ever happen. So basically, at some point, some one needs to sit down study the current field --in particular ActiveSupport's methods, and polish up Facets' Time and DateTime extensions.

The elephant in room here is of course time zone support (ugh).

object_hexid is broken on 32 bit arches with ruby 1.8.7.

ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]

irb(main):001:0> "0x%x" % (Object.new.id << 1)
=> "0x..fb741b4e8"
Note the two dots that should not be there and don't match the output of o.inspect.

This was also broken in facets 2.8.4:

  1. Failure:
    test_object_hexid(TCKernel) [./test/core/kernel/test_object_hexid.rb:8]:
    <"#Object:0xb7248ea4"> expected but was
    <"#Object:0xfb7248ea4">.

In the implementation of this version there is a distinction between RUBY_VERSION < 1.8.7, but this distinction is really between 32bit and 64bit arches.

Hash#delete_values return value

While #delete_values works as expected, it might return something more useful. Currently:

    a = { :a => 1, :b => 2, :c => 3 }
    a.delete_values(1)  #=> [nil, 1, nil]

Symbol#setter?

Maybe Symbol#setter? should actually be called Symbol#writer? Likewise for #plain? and #reader?

Deprecate Kernel#resc

The #resc method isn't needed anymore thanks to String#to_re. Might also consider adding Regexp[].

cluster_by should accept integer argument.

Implemented in git://github.com/LavirtheWhiolet/facets.git

TODO: May be it cluster_by() should be overriden in Array instead of Enumerable because Array preserves order?

TODO: May be group_by() should accept integer instead of cluster_by()?

Bring back __HERE__ (maybe)

Turns out #source_location doesn't really cut it, since it's for Method only.

So should we bring __HERE__ back? It can be defined as:

  def __HERE__
    caller(1).first
  end

Or

  def __HERE__
    caller(1).first.split(':')
  end

If we want to split line from file.

Of course, we might also ask if __HERE__ is the best name for this.

descendents

I think this could well be spelled
descendants
Thanks!
-r

Dir.recursive alias for Find.find

It was reported long ago: "I think it's better to implement Dir.recursive() as alias of Find.find()".

I am not so certain of this, but let us make a note of it here for the time being.

doesn't work with rails 3.0.3

I've tried to use Hashery into a rails 3 project and came across with this bug:
https://github.com/rubyworks/hashery/issues#issue/6

Actually, the bug is triggered by facets.
I've read the solution provided here:
https://github.com/rubyworks/facets/issues/unreads#issue/19

and inserted "require 'facets'" in config/preinitializer.rb
and "gem 'facets'" in the Gemfile but the problem persists:

$ rails console
Loading development environment (Rails 3.0.3)
ruby-1.9.2-p0 > Post
ArgumentError: method does not exist
        from /Users/olistik/.rvm/gems/ruby-1.9.2-p0/gems/facets-2.9.0/lib/core/facets/module/redefine_method.rb:27:in `redefine_method'
        from /Users/olistik/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/associations.rb:1445:in `association_accessor_methods'
        from /Users/olistik/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/associations.rb:1225:in `belongs_to'
        from /Users/olistik/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/autosave_association.rb:137:in `belongs_to'
        from /private/tmp/hashery_test/app/models/post.rb:2:in `<class:Post>'
        from /private/tmp/hashery_test/app/models/post.rb:1:in `<top (required)>'

String.indent_to()

require 'facets/string/indent'

class String

  def indent_to(required_indentation_level, padding_char = ' ')
    raise %(padding_char must be char, not string) if padding_char.length != 1
    return padding_char * required_indentation_level if self.empty?
    current_indentation_level = self.lines.map { |line| line[/^#{"\\" + padding_char}*/].length }.min
    self.indent(required_indentation_level - current_indentation_level, padding_char)
  end

end

"git push" failed

Hi!
I'd like to to something to facets like you described here: http://rubyworks.github.com/facets/source.html. But the push command failed (error code 22) probably becuase of missing writing permissions. To get the changes back to the origin, I need to know whereto put it. Can you give me the correct URL.

thanks!

Rename String#margin to #trim

Seem like #trim is a much more fitting name for what the method actually does.

Of course, the question is, is it worth the loss of backward compatibility?

Module#pathize and #methodize

Consider if these work as they should. Currently camelcase becomes snakecase and module separators become double undescores __. This insures the names can be converted in either direction, but perhaps that isn't necessary?

Incompatible with rails3.0.0.beta4

facets in incompatible with rails3.0.0.beta4. Rails implements its own version of cattr_accessor that can take hash arguments. This conflicts with the version in facets, that triest to handle arguments as a new class variables.
The resulting behaviour is that rails doesn't run when facets is loaded.

rails console

gems/facets-2.8.4/lib/core/facets/class/cattr.rb:35: syntax error, unexpected $undefined (SyntaxError)
unless defined? @@{:instance_writer=>true}
...
from gems/ruby-1.9.2-rc1/bundler/gems/rails-f33ee69/activesupport/lib/active_support/cache.rb:148

Unit tests

Hi! I just forked the HEAD and tried to run tests with rake test:core. After some tests failed (for obsolete String#outdent) I wanted to fix these, but there seem to be two test suites: one based on lemon and the other 'test/unit' ones. Which ones are preferred? How do you run the lemon tests? In any case, the docs should be updated to reflect the changes.

Cannot run facets with Rubinius

Rubinius creates compiled ruby .rbc files in the same directories as its .rb counterparts. This causes an issue with how facets loads its files. Right now it uses:

Dir["dir/*"].each { |x| require x }

it should use

Dir["dir/*.rb"].each { |x| require x }

Facets 2.9.1 breaks Rails 3.1.rc6

I created a brand new Rails 3.1.rc6 project and included facets in the Gemfile. I then created two simple models with an association between them. When I try to load either of the models in rails console, I get the following error:

NoMethodError: private method redefine_method' called for #<Class:0x00000106008c80> from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/base.rb:1082:inmethod_missing'
from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/association.rb:40:in define_readers' from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/singular_association.rb:17:indefine_readers'
from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/association.rb:33:in define_accessors' from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/singular_association.rb:10:indefine_accessors'
from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/association.rb:22:in build' from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/autosave_association.rb:127:inbuild'
from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/belongs_to.rb:14:in build' from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations/builder/association.rb:12:inbuild'
from /Users/andrew/.rvm/gems/ruby-1.9.2-p290@scheduler/gems/activerecord-3.1.0.rc6/lib/active_record/associations.rb:1409:in `belongs_to'

Remove facets and everything works just fine.

Facets defines a private redefine_method in lib/core/facets/module/redefine_module.rb.
Rails defines a similar public redefine_method in lib/active_support/core_ext/module/remove_method.rb

Various parts of rails depend on the the redefine_method being public and loading the facets definition hoses this.

One suggested fix: have facets not define it's method if it is already defined.

requiring 'gem facets' breaks Rails 3.2.1 / facets 2.9.3

I have a brand-new Rails 3.2.1 project, which requires facets, and after you run "bundle install",
when you run "rails console" , this happens:

$ rails --version
3.2.1
$ rails new example
$ cd example
$ vi Gemfile
$ bundle install

$ rails c
/Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/engine.rb:504:in `block in initializers': undefined method `initializers' for #<Instance:0x007fd52b3ae7d0 @delegate=:all> (NoMethodError)
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/engine.rb:500:in `each'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/engine.rb:500:in `initializers'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/application.rb:202:in `initializers'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /private/tmp/DELETEME/config/environment.rb:5:in `<top (required)>'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/application.rb:103:in `require_environment!'
        from /Users/myusername/.rvm/gems/ruby-1.9.2-p180@rails_3.2/gems/railties-3.2.1/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

'string/xor.rb' should be named 'string/op_xor.rb'

string/xor.rb file should probably be called op_xor.rb instead. That's the going procedure so that facets-live.rb will be able to convert operators to names. Hover someone mentioned it seemed rather redundant to use "op" prefix. Perhaps these methods could just have names without the the prefix?

If there are no significant naming conflicts, then getting rid of the op prefix is a possibility. In the mean time a op_xor.rb alias to xor.rb will do the trick.

Facets "Essentials"

Another interesting idea would be to mark a very very few libs as "essential" like "you use these every day" File.write would be one for me. i.e. something like a

require 'facets/essentials'

-Roger Pack

Enumerable#count breaks Pry in Ruby 2.0.0

The Enumerable#count method in https://github.com/rubyworks/facets/blob/master/lib/core/facets/enumerable/count.rb breaks Pry's Pry#update_input_history method:

[1] pry(main)> require 'facets/enumerable/count'
nil
TypeError: nil can't be coerced into Fixnum
from /Users/ashmoran/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/pry-0.9.12/lib/pry/pry_instance.rb:549:in `+'

Any subsequent lines of code added raise a TypeError. The line in Pry that is affected is:

Pry.current_line += code.each_line.count

from https://github.com/pry/pry/blob/master/lib/pry/pry_instance.rb#L532

fix: #recurse doesn't "go deep" with multple classes (Hash/Array)

struct = [1, 2, {:a => 3, :b => [4, 5, {:c=>6}]}, [7, 8]]
struct.recurse(Array, Hash){|o| p o}

I wrongly get:

{:a=>3, :b=>[4, 5, {:c=>6}]}
[7, 8]
[1, 2, {:a=>3, :b=>[4, 5, {:c=>6}]}, [7, 8]]

After my patch[1] you get:

{:c=>6}
[4, 5, {:c=>6}]
{:a=>3, :b=>[4, 5, {:c=>6}]}
[7, 8]
[1, 2, {:a=>3, :b=>[4, 5, {:c=>6}]}, [7, 8]]

Tests pass sucesfully with:

lemon -Ilib/core test/core/array/test_recurse.rb
lemon -Ilib/core test/core/array/test_recurse.rb

You can pull my 'recurse' branch.

TODO: I should probably write new test cases in the next commits...

Guido De Rosa

[1] http://github.com/gderosa/facets/commit/c7d0b48de341a40cff423a9e194e947fbc399ce0

Update documentation

Hello,

It would be helpful for newcomers to update the documentation to show how to make facets work with Rails >3.0.3.
I had to do the following:
Besides including in the gemwile I put the following into "config/preinitializer.rb":

require 'facets'

Then I required "config/preinitializer.rb" in "config/application.rb" just before

require 'rails/all'

Now it works.

Otherwise I was getting the following error:

gems/facets-2.9.1/lib/core/facets/module/redefine_method.rb:29:in undef_method': undefined method some_method' for class `SomeClass' (NameError)

Regards.

Contributor's doc update is needed

What tools should contributor use to run tests and to build the gem (seriously, I have downloaded source code, have made some fix but could not do anything with it)? How to publish the gem or who is responsible for publishing? All these things should be described in documentation for contributors.

Patch: Indexable::rand

I have forked facets to add a rand() method to Indexable, which returns a random element. It's at git://github.com/CraigCottingham/facets.git in the indexable_rand branch.

I haven't tested it yet, because I haven't figured out how to either tell Ruby to use my working copy of facets instead of the installed gem, or how to make a new gem from my working copy. There's no .gemspec in the working directory. I found the install/uninstall tasks in Rakefile, but those don't seem to work correctly (install created core/ and more/ directories in my site_ruby/1.9.1 directory, rather than under a facets/ directory).

For now I'm going to overwrite indexable.rb in my gem tree, but even I know that's a hack and half. Any suggestions on how to do this properly will be gratefully welcomed.

Various enhancements

  1. String#include? should accept Regexp-s.
  2. Enumerable#has?() and Enumerable#have?() using "===" equality test.
  3. StringScanner#scan_before().
  4. SafeOpenStructable class.

All these are implemented in git://github.com/LavirtheWhiolet/facets.git

Shellwords#escape in Windows? (2)

Here is the code:

def escape(cmdline)
  '"' + cmdline.gsub(/\\(?=\\*\")/, "\\\\\\").gsub(/\"/, "\\\"").gsub(/\\$/, "\\\\\\").gsub("%", "%%") + '"'
end

And here is test case:

"a"\"b\c\\"d e\f\ def {ghi} jkl; %x12% \%123"% zya\

This string, transformed with specified #escape(), is interpreted by Windows shell exactly as written above.

I don't know where to put it in Facets, because this code is for Windows only. The code should somehow determine whether it is running in Windows or *nix.

P. S. I have noticed that #escape() for *nix does not escape "${env var}" macros. Is it correct? Nevertheless, I have made escaping of analogous macros ("%env var%") in Windows (because it works too tricky). If it is not needed then just remove ".gsub("%", "%%")" in the code above.

P. P. S. Sorry, accidentally closed the issue...

[doc] errors on Core:Enumerable#commonality

The block code in the doc for this method is erroneous.
http://facets.rubyforge.org/apidoc/api/core/classes/Enumerable.html#M000511

From an irb session:


ruby-1.9.1-p378 > [1, 2, 2, 3, 4, 4].commonality
 => {2=>[2, 2], 4=>[4, 4]} 
ruby-1.9.1-p378 > ["foo", "bar", "a"].commonality { |str| str.length }
 => {3=>["foo", "bar"]}

The collision method mentionned in the doc doesn't seem to be an existing alias of commonality (could be interesting to add it though!).

Range#at_rand() enhancement.

(x..y).at_rand() should return random floating point number (whether Float, BigNum or whatever else) if x and y are floating point numbers.

Also (x..y).at_rand() should not convert the range to array when possible.

Also (x..y).at_rand() should return y sometimes but (x...y).at_rand() should never return y.

no such file to load -- facets/methodspace (MissingSourceFile)

Trying to use unroller in a rails 2.3.14 legacy project I inherited. This is what I get:

$ gem install unroller --include-dependencies
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Successfully installed facets-2.9.3
Successfully installed quality_extensions-1.3.1
Successfully installed colored-1.2
Successfully installed unroller-1.0.0

$ ruby script/server
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- facets/methodspace (MissingSourceFile)
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `block in require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/unroller-1.0.0/lib/unroller.rb:4:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:33:in `require'
  from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `block in require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require'
  from /mathworks/home/lkyrala/perforce/legacy_rails_app/1.41/config/initializers/unroller_local_dev_trace_patch.rb:21:in `<top (required)>'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:171:in `load'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:171:in `block in load_with_new_constant_marking'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:171:in `load_with_new_constant_marking'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/initializer.rb:622:in `block in load_application_initializers'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/initializer.rb:621:in `each'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/initializer.rb:621:in `load_application_initializers'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/initializer.rb:176:in `process'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/initializer.rb:113:in `run'
  from /mathworks/home/lkyrala/perforce/legacy_rails_app/1.41/config/environment.rb:6:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `block in require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require'
  from /local/rvm/gems/ruby-1.9.2-p318@legacy_rails_app/gems/rails-2.3.14/lib/commands/server.rb:84:in `<top (required)>'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from <internal:lib/rubygems/custom_require>:29:in `require'
  from script/server:3:in `<main>'

IndexError: key not found

I'm attempting to use Dictionary in a Rails 2.3.8 project. This is gem version 2.9.1, and it's Ruby Enterprise Edition 1.8.7.

Upon startup of the application, I'm presented with this error:

/gems/facets-2.9.1/lib/core/facets/hash/slice.rb:11:in `fetch':IndexError: key not found

This is whether I'm running the app via Passenger or even if I attempt to fire up a console.

Is there some additional requirement to using this library that I have missed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.