When chaining methods can the child method access and use the results of the 'parent' method? (i.e. Object.parent.child)
<p><strong>Description</strong>
I've created a <code>Report</code> object that has different environments/groups (:live &amp; :demo) which are simply arrays that will be populated with <code>ReportItem</code> objects which have the following attributes <code>:currency, :gross, :net</code> (And Gross &amp; Net hold Ruby Money objects).</p>

<p>In the <code>Report.rb</code> class there are two methods called <code>add_money_to_net</code> and <code>add_money_to_gross</code> both have a variable I temporarily named <code>@group</code></p>

<p><strong>Question</strong>
(<code>report = Report.new</code>)
What I'm trying to do is is chain methods like this <code>report.demo.add_money_to_gross(&lt;params&gt;)</code> if this method is called i would like to have access to <code>report.demo</code> (in place of my <code>@group</code> variable). Alternatively calling <code>report.live.add_money_to_gross(&lt;params&gt;)</code> should let me access <code>report.live</code>. Is this possible?</p>

<p>I hope this makes sense. Please let me know if anything is unclear.</p>

<p><strong>Report.rb</strong></p>

<pre class="lang-rb prettyprint-override"><code>class Report
  include ActiveModel::Model
  attr_accessor :demo, :live

  def initialize
    @demo = []
    @live = []
  end

  def demo
    @demo
    self
  end

  def live
    @live
    self
  end

  def add_money_to_net(money)
    add_money(group: @group, money: money)
  end

  def add_money_to_gross(money)
    add_money(group: @group, money: money)
  end

  private

  def add_money(group:, money:)
    item = group.find {|s| s.currency == money.currency }
    if item
      item.net += money
    else
      group &lt;&lt; ReportItem.new(currency: money.currency.to_s, net: money)
    end
  end
end
</code></pre>

<p><strong>ReportItem.rb</strong></p>

<pre class="lang-rb prettyprint-override"><code>class ReportItem
  include ActiveModel::Model
  attr_accessor :currency, :gross, :net

  def initialize(currency:, gross: nil, net: nil)
    @currency = currency
    @gross = gross ? gross : Money.new(0, currency)
    @net = net ? net : Money.new(0, currency)
  end

  def gross=(value)
    @gross = value if @gross.currency == @currency
  end

  def net=(value)
    @net = value if @net.currency == @currency
  end
end
</code></pre>