Class: ComparableArray

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_rails_extensions/comparable_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ ComparableArray

Returns a new instance of ComparableArray.



4
5
6
# File 'lib/rspec_rails_extensions/comparable_array.rb', line 4

def initialize array
  @array = array.dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rspec_rails_extensions/comparable_array.rb', line 16

def method_missing method, *args
  if array.respond_to?(method)
    array.send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#arrayObject (readonly)

Returns the value of attribute array.



2
3
4
# File 'lib/rspec_rails_extensions/comparable_array.rb', line 2

def array
  @array
end

Instance Method Details

#=~(other_array) ⇒ Object



8
9
10
# File 'lib/rspec_rails_extensions/comparable_array.rb', line 8

def =~ other_array
  array.size == other_array.size && array.all? {|e| other_array.include?(e) }
end

#inspectObject



12
13
14
# File 'lib/rspec_rails_extensions/comparable_array.rb', line 12

def inspect
  array.inspect
end