Class: Array
- Inherits:
-
Object
- Object
- Array
- 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
Instance Method Summary collapse
-
#key?(key_obj) ⇒ Boolean
Returns true if this Array has the specified index.
-
#keys ⇒ Object
Returns an Array of all the valid indices for this Array.
Methods included from KeyDial::Coercion::Arrays
Methods included from KeyDial::Coercion::Coercer
Methods included from KeyDial
Instance Method Details
#key?(key_obj) ⇒ Boolean
Returns true if this Array has the specified index.
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 |
#keys ⇒ Object
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 |