Class: Array

Inherits:
Object
  • Object
show all
Includes:
KeyDial, KeyDial::Coercion::Arrays
Defined in:
lib/key_dial.rb

Overview

Bring Array and Struct into parity with Hash for key? and fetch Will not redefine these methods if they already exist, either from some future Ruby version or another gem

Constant Summary

Constants included from KeyDial

KeyDial::VERSION

Instance Method Summary collapse

Methods included from KeyDial::Coercion::Arrays

included

Methods included from KeyDial::Coercion::Coercer

#to

Methods included from KeyDial

#call, #to_dial

Instance Method Details

#key?(key_obj) ⇒ Boolean

Returns true if this Array has the specified index.

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/key_dial.rb', line 44

def key?(key_obj)
	if key_obj.is_a?(Numeric) && key_obj.respond_to?(:to_i)
		key = key_obj.to_i
		return key.magnitude + (key <= -1 ? 0 : 1) <= self.size
	else
		return false
	end
end

#keysObject

Returns an Array of all the valid indices for this Array



54
55
56
57
58
59
60
# File 'lib/key_dial.rb', line 54

def keys
	if self.size > 0
		return Array(0..(self.size - 1))
	else
		return []
	end
end