Override []

How can i over ride [] in a class?

i have a binary class where it is stored in a string and i want to
beable to do this
a=Binary.new("00101001")
p a[0] >> 1

i can provide what i have so far if you would like.
thank you for your time.
Becker

class Foo
  def ( n )
    #...
  end
end

···

On Nov 23, 2004, at 7:15 PM, ruby talk wrote:

How can i over ride in a class?

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

···

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

"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
>
>