Robert Klemme
11/24/2004 9:23:00 AM
"ruby talk" <rubytalk@gmail.com> schrieb im Newsbeitrag
news:25094bf704112400141ba74831@mail.gmail.com...
> def = (n)
> @f = n if n.type==String
>
> end
>
> C:/1134re.rb:20: syntax error
> def = (n)
> ^
> C:/1134re.rb:20: warning: don't put space before argument parentheses
> C:/1134re.rb:207: syntax error
>
> sorry this is my first class
You cannot override assignment. You can only override []= like in
class Foo
def []=(x,y)
puts "called [#{x}]=#{y}"
end
end
>> Foo.new[1]=2
called [1]=2
=> 2
robert
>
>
> On Wed, 24 Nov 2004 11:56:48 +0900, Gavin Kistner <gavin@refinery.com>
wrote:
> > On Nov 23, 2004, at 7:15 PM, ruby talk wrote:
> > > How can i over ride [] in a class?
> >
> > class Foo
> > def []( n )
> > #...
> > end
> > end
> >
> >
>
>