Class: PathBuilder
- Inherits:
-
Object
show all
- Defined in:
- lib/pathbuilder.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PathBuilder.
4
5
6
7
|
# File 'lib/pathbuilder.rb', line 4
def initialize(*args)
@path = []
@params = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
14
15
16
17
18
|
# File 'lib/pathbuilder.rb', line 14
def method_missing(method, *args)
@path << method
args.each { |arg| arg.is_a?(Hash) ? @params.merge!(arg) : @path << arg }
self
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
2
3
4
|
# File 'lib/pathbuilder.rb', line 2
def params
@params
end
|
Instance Method Details
#[](*args) ⇒ Object
9
10
11
12
|
# File 'lib/pathbuilder.rb', line 9
def [](*args)
@path += args
self
end
|
#inspect ⇒ Object
25
26
27
|
# File 'lib/pathbuilder.rb', line 25
def inspect
"#<#{self.class} @path=\"#{self.to_s}\" @params=#{@params.inspect}>"
end
|
#to_s ⇒ Object
Also known as:
path
20
21
22
|
# File 'lib/pathbuilder.rb', line 20
def to_s
"/#{@path.join("/")}"
end
|