botp
5/27/2009 4:32:00 AM
On Wed, May 27, 2009 at 8:26 AM, Oliver Saunders
<oliver.saunders@gmail.com> wrote:
> Initialize doesn't appear to get called.
>
> class Object
> =A0def initialize
> =A0 =A0@foo =3D 'bar'
> =A0end
> =A0attr_reader :foo
> end
>
> a =3D Object.new # =3D> #<Object:0x54c964 @foo=3D"bar">
see relation bw initialize and new
> a.foo # =3D> "bar"
> 'string'.foo # =3D> nil
> //.foo # =3D> nil
>
> I want to have //.foo and 'string.foo give me "bar" as they should. How
> can I do that?
try defining a method, eg
>> class Object
>> def foo
>> "bar"
>> end
>> end
=3D> nil
>> 1.foo
=3D> "bar"
>> //.foo
=3D> "bar"