Module: Enumerable

Defined in:
lib/fuby/splat.rb,
lib/fuby/invert.rb,
lib/fuby/member.rb,
lib/fuby/to_tok.rb,
lib/fuby/matches.rb,
lib/fuby/part_of.rb,
lib/fuby/to_hash.rb,
lib/fuby/deep_each.rb,
lib/fuby/dimension.rb,
lib/fuby/equivalence.rb,
lib/fuby/longest_common.rb,
lib/fuby/matches_part_of.rb,
lib/fuby/eql_componentwise.rb,
lib/fuby/matches_componentwise.rb

Overview

can’t refine Module

Instance Method Summary collapse

Instance Method Details

#deep_each(*path, &blk) ⇒ Object



4
5
6
7
8
9
# File 'lib/fuby/deep_each.rb', line 4

def deep_each *path, &blk
  each_with_index_or_key do |e, i|
    return e.deep_each i, *path, &blk if self.class === e
    return yield e, *path
  end
end

#dimensionObject



18
19
20
# File 'lib/fuby/dimension.rb', line 18

def dimension
  count
end

#eql_componentwise?(that) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/fuby/eql_componentwise.rb', line 6

def eql_componentwise? that
  each_with_index_or_key.all? { |e, k| e == that[k] }
end

#equivalence?(eq = :eql?) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/fuby/equivalence.rb', line 6

def equivalence? eq = :eql?
  each_cons(2).splat.all? { |fst, snd| fst.send eq, snd }
end

#invertObject



8
9
10
# File 'lib/fuby/invert.rb', line 8

def invert
  ::Hash[ each_with_index_or_key.to_a ]
end

#longest_common_prefix(*those) ⇒ Object



6
7
8
# File 'lib/fuby/longest_common.rb', line 6

def longest_common_prefix *those
  zip(*those).take_while(:equivalence?).map(:first)
end

#longest_common_suffix(*those) ⇒ Object



10
11
12
# File 'lib/fuby/longest_common.rb', line 10

def longest_common_suffix *those
  zip(*those).map(&:reverse).take_while(:equivalence?).map(:first).map(&:reverse)
end

#matches?(that) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/fuby/matches.rb', line 4

def matches? that
  count == that.count and matches_componentwise? that
end

#matches_componentwise?(that) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/fuby/matches_componentwise.rb', line 6

def matches_componentwise? that
  each_with_index_or_key.all? { |e, k| e === that[k] }
end

#matches_part_of?(that) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/fuby/matches_part_of.rb', line 7

def matches_part_of? that
  count <= that.count and matches_componentwise? that
end

#part_of?(that) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/fuby/part_of.rb', line 7

def part_of? that
  count <= that.count and eql_componentwise? that
end

#splatObject



4
5
6
# File 'lib/fuby/splat.rb', line 4

def splat
  ::Enumerator.new { |result| each { |sig| result.<< *sig } }
end

#to_hashObject Also known as: to_h



9
10
11
# File 'lib/fuby/to_hash.rb', line 9

def to_hash
  {}.tap { |hash| each_with_index_or_key { |val, key| hash[key] = val } }
end

#to_tokObject



5
6
7
# File 'lib/fuby/to_tok.rb', line 5

def to_tok
  ::Proc.new &method(:[])
end