Gioele Barabucci wrote:
> When I try to run the attached code (ar2.rb) with ruby 1.8.2 I get the
> following error:
>
> ./ar2.rb:41:in `packDecl': undefined method `packDecl' for
> "\000\000\000\005\000\000\000\002":String (NoMethodError)
>         from ./ar2.rb:27:in `pack'
>         from ./ar2.rb:54
>         from ./ar2.rb:49:in `each'
>         from ./ar2.rb:49
>
> It seems like "\0\0\0\5\0\0\0\2".packDecl is called instead of
> super.packDecl. Did I overwrite 'super'? Where?
>
>
>
> #!/usr/bin/env ruby
> require 'pp'
>
> BASE_INFO = 0x2
>
> class StreamData
> 	attr_accessor :typeDataLength
> 	attr_accessor :type
>
> 	attr_accessor :payloadLength
>
> 	def initialize
> 		@typeDataLength = 0
> 		@payloadLength = 0
> 	end
>
> 	def packDecl
> 		length = @typeDataLength + @payloadLength
> 		return [length, @type].pack("LI")
> 	end
>
> 	def packTypeData
> 		return Array.new
> 	end
>
> 	def pack
> 		return packDecl + packTypeData
> 	end
> end
>
> class BaseInfoData < StreamData
> 	attr_accessor :name
>
> 	def initialize
> 		super
> 		@type = BASE_INFO
> 	end
>
> 	def packDecl
> 		@typeDataLength = [@name].pack("a*").length
> 		return super.packDecl

The problem is that super is not an object; it's the superclass'
implementation of the current method. So you are calling the method
packDecl on the result of StreamData's packDecl method, which is a
packed data string.