Power One wrote:
> Plus from now on, if something looks like an array but without the index 
> (ex: options[3]), then I can safely assumed it's a form of hash but in a 
> reading stage.

Any object can implement its own [] method with whatever semantics it 
likes, not just Arrays and Hashes. The [] method is used for lots of 
different purposes in the Ruby standard classes:

# Testing individual bits in an integer
irb(main):001:0> 15[2]
=> 1

# Substrings
irb(main):002:0> "abcdefg"["cd"]
=> "cd"
irb(main):003:0> "abcdefg"[/d./]
=> "de"

# Filename globbing
irb(main):004:0> Dir["/etc/*"]
=> ["/etc/fstab", "/etc/X11", "/etc/acpi", "/etc/alternatives", 
"/etc/apm" ...]

# Procs
irb(main):005:0> adder = lambda { |x,y| x+y }
=> #<Proc:0xb7d968d8@(irb):7>
irb(main):006:0> adder[4,5]
=> 9

And you can define your own:

  class Bot
    def [](key)
      ...
    end
    def []=(x,y)
      ...
    end
  end
-- 
Posted via http://www.ruby-forum.com/.