class Array

Public Instance Methods

to_hash_as_keys(starting_value = 0, &block)
Alias for: to_hash_keys
to_hash_as_values(starting_key = 0, &block)
Alias for: to_hash_values
to_hash_keys(starting_value = 0, &block) click to toggle source
# File lib/finishing_moves/array.rb, line 20
def to_hash_keys(starting_value = 0, &block)
  t = {}
  block = proc { starting_value } unless block_given?
  each do |entry|
    t[entry] = block.call entry
  end
  t
end
Also aliased as: to_hash_as_keys
to_hash_values(starting_key = 0, &block) click to toggle source
# File lib/finishing_moves/array.rb, line 3
def to_hash_values(starting_key = 0, &block)
  key = starting_key
  block = proc { |key| key + 1 } unless block_given?
  t = {}
  each do |entry|
    t[key] = entry
    key = block.call key
  end
  t
end
Also aliased as: to_hash_as_values
to_indexed_hash(starting_key = 0) click to toggle source
# File lib/finishing_moves/array.rb, line 15
def to_indexed_hash(starting_key = 0)
  raise ArgumentError, "#{starting_key.inspect} is not an integer" unless starting_key.is_a? Integer
  to_hash_values(starting_key)
end
to_sym_loose() click to toggle source
# File lib/finishing_moves/array.rb, line 38
def to_sym_loose
  map do |x|
    if x.respond_to?(:to_sym)
      x.to_sym
    else
      x
    end
  end
end
to_sym_loose!() click to toggle source
# File lib/finishing_moves/array.rb, line 48
def to_sym_loose!
  map! do |x|
    begin
      x.to_sym
    rescue NoMethodError => e
      x
    rescue Exception
      raise
    end
  end
end
to_sym_strict() click to toggle source
# File lib/finishing_moves/array.rb, line 30
def to_sym_strict
  map { |x| x.to_sym }
end
to_sym_strict!() click to toggle source
# File lib/finishing_moves/array.rb, line 34
def to_sym_strict!
  map! { |x| x.to_sym }
end