class AmpersandX::Proxy

Public Class Methods

method_missing(name, *args) click to toggle source
# File lib/ampersand_x.rb, line 11
def method_missing(name, *args)
  new([[name, *args]])
end
new(path = []) click to toggle source

Initialize a Proxy.

@param path [Array<Array>] path array

# File lib/ampersand_x.rb, line 21
def initialize(path = [])
  @path = path
end

Public Instance Methods

actual(x) click to toggle source

Get the actual value after calling all methods from path.

@param x [Object] object to call path methods on

# File lib/ampersand_x.rb, line 32
def actual(x)
  @path.reduce(x) { |memo, prop| memo.send(*prop) }
end
method_missing(*args) click to toggle source
# File lib/ampersand_x.rb, line 25
def method_missing(*args)
  self.class.new(@path + [args])
end
to_proc() click to toggle source

Convert proxy to a proc.

# File lib/ampersand_x.rb, line 37
def to_proc
  -> x { actual(x) }
end