Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 2.x Array#to_set removed #34

Closed
davidcoallier opened this issue Mar 3, 2014 · 1 comment
Closed

Ruby 2.x Array#to_set removed #34

davidcoallier opened this issue Mar 3, 2014 · 1 comment

Comments

@davidcoallier
Copy link

Description

Cistern's collection.rb uses to_set on BLACKLISTED_ARRAY_METHODS which is an Array.

However, in Ruby 2.x (http://www.ruby-doc.org/core-2.0/Array.html, http://www.ruby-doc.org/core-2.1.1/Array.html), the to_set method has been removed.

Expected Behaviour

Be able to use and run cistern in Ruby 2.x which is the default OSX version in Mavericks.

Actual Behaviour

Exception is thrown when using the collections:

/Library/Ruby/Gems/2.0.0/gems/cistern-0.5.3/lib/cistern/collection.rb:9:in `<class:Collection>': undefined method `to_set' for #<Array:0x007f8f4a3220b8> (NoMethodError)

How to reproduce

Instantiate a Collections object and invoke BLACKLISTED_ARRAY_METHODS

Possible Fix

Due to my restricted knowledge of Ruby and how to best include scripts, I could only test the fix with what I've been given :)

In collections.rb I've done the following:

require 'set'

class Cistern::Collection
  extend Cistern::Attributes::ClassMethods
  include Cistern::Attributes::InstanceMethods

  BLACKLISTED_ARRAY_METHODS = Set.new [
    :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
    :shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
    :keep_if, :pop, :shift, :delete_at, :compact
  ] # :nodoc

This appears to fix the issue. Should I make a pull-request with this?

@lanej
Copy link
Owner

lanej commented Mar 3, 2014

2.1.1 :001 > [].to_set
NoMethodError: undefined method `to_set' for []:Array
    from (irb):1
    from /Users/jlane/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'
2.1.1 :002 > require 'set'
true
2.1.1 :003 > [].to_set
[]

i believe that one of the test dependencies has the side effect of requiring set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants