Class: Leto::Path
Instance Attribute Summary collapse
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(start:, steps: []) ⇒ Path
constructor
A new instance of Path.
- #inspect ⇒ Object (also: #to_s)
- #resolve ⇒ Object
- #size ⇒ Object (also: #count)
Constructor Details
#initialize(start:, steps: []) ⇒ Path
Returns a new instance of Path.
8 9 10 11 |
# File 'lib/leto/path.rb', line 8 def initialize(start:, steps: []) @start = start @steps = steps end |
Instance Attribute Details
#start ⇒ Object (readonly)
Returns the value of attribute start.
6 7 8 |
# File 'lib/leto/path.rb', line 6 def start @start end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
6 7 8 |
# File 'lib/leto/path.rb', line 6 def steps @steps end |
Instance Method Details
#+(other) ⇒ Object
22 23 24 |
# File 'lib/leto/path.rb', line 22 def +(other) self.class.new(start: start, steps: steps + other.to_a) end |
#==(other) ⇒ Object
32 33 34 |
# File 'lib/leto/path.rb', line 32 def ==(other) other.to_a == steps end |
#each(&block) ⇒ Object
13 14 15 |
# File 'lib/leto/path.rb', line 13 def each(&block) steps.each(&block) end |
#inspect ⇒ Object Also known as: to_s
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/leto/path.rb', line 36 def inspect start_str = start.inspect start_str = "#{start_str[0..38]}…#{start_str[-1]}" if start_str.size > 40 [ "#<#{self.class} #{start_str}", steps.map do |method, *args| args_str = args.map(&:inspect).join(', ') if method == :[] "[#{args_str}]" else ".#{method}#{"(#{args_str})" unless args_str.empty?}" end end, ">" ].join end |
#resolve ⇒ Object
26 27 28 29 30 |
# File 'lib/leto/path.rb', line 26 def resolve steps.inject(start) do |obj, (method, *args)| obj&.send(method, *args) or break obj end end |
#size ⇒ Object Also known as: count
17 18 19 |
# File 'lib/leto/path.rb', line 17 def size steps.size end |