Class: Array

Inherits:
Object show all
Defined in:
lib/temporals/ruby_ext.rb

Direct Known Subclasses

Temporal::ArrayOfRanges

Instance Method Summary collapse

Instance Method Details

#include_value?(v) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/temporals/ruby_ext.rb', line 12

def include_value?(v)
  any? do |iv|
    case iv
    when Range || Array
      v.in?(iv)
    else
      if iv.to_s =~ /^\d+$/ && v.to_s =~ /^\d+$/
        iv.to_i == v.to_i
      else
        puts "Comparing #{iv} with #{v}" if $DEBUG
        iv == v
      end
    end
  end
end

#includes_sequence?(sequence) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
# File 'lib/temporals/ruby_ext.rb', line 2

def includes_sequence?(sequence)
  first_exists = []
  each_index do |i|
    first_exists << i if self[i] == sequence[0]
  end
  first_exists.any? do |i|
    return i if self[i...(i+sequence.length)] == sequence
  end
end