Search Results

Search found 2 results on 1 pages for 'nicholaides'.

Page 1/1 | 1 

  • Rspec: "array.should == another_array" but without concern for order

    - by nicholaides
    I often want to compare arrays and make sure that they contain the same elements, in any order. IS there a consise way to do this in RSpec? Here are methods that aren't acceptable: #to_set For example: array.to_set.should == another_array.to_set This fails when the arrays contain duplicate items. #sort For example: array.sort.should == another_array.sort This fails when the arrays elements don't implement #<=> #size and #to_set For example: array.to_set.should == another_array.to_set array.size.should == another_array.size This would work, but there's got to be a better way.

    Read the article

  • Ruby - overriding/enabling multiple assignment (e.g. `a, b, c = d, e, f`)

    - by nicholaides
    In ruby, you can do this: d = [1, 2, 3] a, b, c = d a, b, and c, will receive the values 1, 2, and 3, respectively. d, in this case in an Array and ruby knows to assign it's contents to a, b, and c. But, if d were a Fixnum, for example, only a would be assigned to the value of d while b and c would be assigned nil. What properties of d allow it to be used for multiple assignment? In my exploring so far, I've only been able to make instances of subclasses of Array behave in this way.

    Read the article

1