So, for whatever reason there is no peek method in the ruby core Queue class. I am trying to create a child class that implements the peek method. However, I don't understand why I am getting an error. Is it not possible to use instance variables in this way? Looking at the source code for Queue, there are instance variables in the constructor of the parent class. Is there a way to reference these in the subclass?

class PeekQueue < Queue def peek @mutex.synchronize{ while true if @que.empty? raise ThreadError, "queue empty" if non_block @waiting.push Thread.current @mutex.sleep else return @que[0] end end } end end a = PeekQueue.new a.push(1) a.peek NoMethodError: undefined method 'synchronize' for nil:NilClass

Edit: The Queue class is created at compile time, which is why I couldn't find the source on the ruby source code on github. This is what the parent class looks like: https://gist.github.com/anonymous/574e20fea3a28663bfe2