Class: KeyPath::Path
- Inherits:
-
Object
- Object
- KeyPath::Path
- Defined in:
- lib/key_path/path.rb
Overview
The class representing a Path in a collection object.
Instance Method Summary collapse
-
#initialize(path = '') ⇒ Path
constructor
A new instance of Path.
- #inspect ⇒ Object
- #parent ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path = '') ⇒ Path
Returns a new instance of Path.
4 5 6 |
# File 'lib/key_path/path.rb', line 4 def initialize(path = '') @path = path end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/key_path/path.rb', line 27 def inspect "#<#{self.class.name}:#{object_id} path=#{@path}>" end |
#parent ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/key_path/path.rb', line 8 def parent s = to_a s.pop # there's no parent if it's empty return nil if s == [] # otherwise, join them back together and pass back a path s.join('.').to_keypath end |
#to_a ⇒ Object
23 24 25 |
# File 'lib/key_path/path.rb', line 23 def to_a @path.split('.') end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/key_path/path.rb', line 19 def to_s @path end |