Q:

What's happening with array.last[x]?

I came across this:
a = [1, 2, 3, 4, 5, 6, 7]
a.last # => 7
a.last[-1] # => 0
a.last[0] # => 1
a.last[1] # => 1 
a.last[100] # => 0

Can someone explain what's happening and why?

A:

Array#last returns the last element, i.e. 7. Appending [] simply calls Fixnum#[], returning the number's nth bit:
7[0]   # => 1
7[1]   # => 1 
7[2]   # => 1 
7[3]   # => 0
# ... 
7[100] # => 0

7.to_s(2) #=> "111"

