title: Ruby how to call a class setter with yield
body: <p>I was able to get my code working, but I don't like the way it works syntaxually - not sure if that is even a word.</p>
  
  <h3>My code currently:</h3>
  
  <pre><code>user.set_phone(phone) do
    message = "Verify your phone number #{@host}/phone/verify?id=#{user.id}&amp;code=#{user.phone_verification_code}"
    CoreIntegrations::Sinch.send_text(message, phone)
  end
  </code></pre>
  
  <h3>How I would like it to look/work:</h3>
  
  <pre><code>user.phone=(phone) do
    message = "Verify your phone number #{@host}/phone/verify?id=#{user.id}&amp;code=#{user.phone_verification_code}"
    CoreIntegrations::Sinch.send_text(message, phone)
  end
  </code></pre>
  
  <h3>This is the Error I'm getting</h3>
  
  <pre><code>/Users/christianjuth/Desktop/apollo-8/app/controllers/application_controller.rb:140: syntax error, unexpected keyword_do, expecting keyword_end /Users/christianjuth/Desktop/apollo-8/app/controllers/application_controller.rb:267: syntax error, unexpected keyword_end, expecting end-of-input
  </code></pre>
  
  <p><em>The line number might in sync with the repo, case I have some local changes made to the application controller.</em></p>
  
  <p>...Or something along those lines. <code>user</code> is an ActiveRecord model. The reason I want to do this, is yield only gets called if the variable <code>phone</code> sent into <code>user.phone=</code> is different from the existing value of <code>user.phone</code>. </p>
  
  <p>I think this is more of a syntax issue, but just in case <a href="https://github.com/space-hanger/apollo-8/tree/731ba44f5a13f5d8a3e0b13414af371ce3f4f817" rel="nofollow noreferrer">here is repo</a> for context. The code you are looking at lives in <code>app/controllers/application_controller.rb</code>, and the user model can be found in <code>user/models/user.rb</code>.</p>
  
  <h3>UPDATE: I am having trouble calling the setter with yield not defining it. Sorry for the confusion.</h3>