On Tue, Feb 1, 2011 at 7:11 PM, Jim Carter <jcarter / leupold.com> wrote:
> I have the following configuration:
>
> class ExternalBallistics
>
> =A0 =A0attr_accessor =A0 =A0:a,:b =A0 #inputs
> =A0 =A0attr_reader =A0 =A0 =A0:c =A0 =A0 =A0#outputs
>
> =A0 =A0def initialize(&block)
> =A0 =A0 instance_eval &block
> =A0 =A0end
>
> =A0 =A0def calculate
> =A0 =A0 =A0 c =3D a + b

This is not calling the method "c=3D", not that you have one, in any
case. "c" is considered a local variable.
Change it to:

@c =3D a + b

to set the value in the instance variable that your reader will access.

> =A0 =A0end
>
> end #class
>
>
>
> ExternalBallistics.new do
>
> =A0 self.a =3D 5
> =A0 self.b =3D 3
>
> =A0 calculate
>
> =A0 puts self.c
>
> end #ExternalBallistics
>
>
> This returns a nil value for c. =A0If I use "puts" inside of def
> calculate, I will get 8 for an answer. =A0Why does a and b act globally
> and c not. =A0Am I forced to use a return on calculate to get an answer.
> If I do so, do I still need to define an attr_reader :c (what use is it
> then) ?
>
>
> Thanks

Jesus.