Class: WebFunction::Promise::Path
- Inherits:
-
Object
- Object
- WebFunction::Promise::Path
- Defined in:
- lib/web_function/promise.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
- #mutate(path) ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ Path
10 11 12 |
# File 'lib/web_function/promise.rb', line 10 def initialize(path) @path = path end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/web_function/promise.rb', line 22 def [](key) case key when String, Symbol mutate("#{@path}.#{key}") when Integer mutate("#{@path}[#{key}]") else raise ArgumentError end end |
#mutate(path) ⇒ Object
33 34 35 |
# File 'lib/web_function/promise.rb', line 33 def mutate(path) Path.new(path) end |
#to_json(*args) ⇒ Object
18 19 20 |
# File 'lib/web_function/promise.rb', line 18 def to_json(*args) @path.to_json(*args) end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/web_function/promise.rb', line 14 def to_s @path end |