sur max wrote:
> But i think there is a point to discuss here...
> 
> as lf1.name is simply an instance method which is(should be) only 
> capable of
> returning the instance variable "@name"
> 
> so by defining :name as attr_reader should block everything which is trying
> to write the instance variable "@name"

Nothing is trying to write to @name - what's happening is that @name 
modifies its own data via the method call '<<' (or gsub!, or...).

Watch:

irb(main):001:0> class A; attr_reader :foo; def initialize; @foo=''; 
end; end
=> nil
irb(main):002:0> a = A.new
=> #<A:0xb7ca0280 @foo="">
irb(main):003:0> a.foo.object_id
=> -605748948
irb(main):004:0> a.foo = "Foo!"
NoMethodError: undefined method `foo=' for #<A:0xb7ca0280 @foo="">
         from (irb):4
         from :0
irb(main):005:0> a.foo << "Foo!"
=> "Foo!"
irb(main):006:0> a.foo
=> "Foo!"
irb(main):007:0> a.foo.object_id
=> -605748948

See how despite the method call, a.foo.object_id returns the same value 
each time?  That's what attr_reader protects.  It's not within the scope 
of what attr_reader should be doing to define what methods you're 
allowed to call on what it returns, because it's got no way to know 
which methods can change that object's state.

Hope this helps,
-- 
Alex

> 
> 
> 
> On 2/16/07, sur max <sur.max / gmail.com> wrote:
>>
>> It means even need not to go for lf1.instance_variable_set
>>
>> it is pretty working as
>>
>> lf1.name.gsub!(/.*/,"")
>>
>> lf1.name << "new broken name"
>>
>> On 2/16/07, dblack / wobblini.net <dblack / wobblini.net> wrote:
>> >
>> > Hi --
>> >
>> > On Fri, 16 Feb 2007, sur max wrote:
>> >
>> > > Hi David,
>> > >
>> > > Now this should not be available !!
>> > >
>> > > lf1.name << "more stuffs"
>> > > this should generate error !! ... (i agree it is working)
>> >
>> > Strings response to "<<", so assuming lf1.name returns a string,
>> > there's no error of any kind here.
>> >
>> > > but is name is an attr_reader then the manipulations with "<<" should
>> > not be
>> > > supported, as the case of "="
>> > > or it should be ?
>> >
>> > It's not really that = is or is not supported; it's all a matter of
>> > what methods you define.  If you define a method that returns a
>> > string, then you get a string, which is mutable, from that method.
>> > The notion of an "attribute" is really in the mind of the programmer.
>> > Objects don't know whether they're attributes or not; they just exist,
>> > and do what they're told.
>> >
>> >
>> > David
>> >
>> > --
>> > Q. What is THE Ruby book for Rails developers?
>> > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black )
>> >     (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
>> > Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
>> > A. Ruby Power and Light, LLC ( http://www.rubypal.com)
>> >
>> >
>>
>>
>> -- 
>> sur
>> http://expressica.com
> 
> 
> 
>