class Generic
  
  @@router=''
  @@digit=''
  @@data=''
  def initialize(str)
    @str=str
  end
  #def seperate
  #  @str="434 <user;password>##ROUTER=BROKER_NAME##"
    #puts @str.split()
   def digit
    @digit=@str[0,3]
    puts "Digit Part: " +@digit
  end
  def data
    @data=@str[/<[a-z]*;[a-z]*>/]
    puts "Data Part: " +@data
  end
  def router  
    @router=@str[/##[A-Z]*=[A-Z]*_[A-Z]*##/]
    puts "Router part: " +@router
 end
end

class Sub < Generic
  
end
   




genericobj=Generic.new('434 <user;password>##ROUTER=BROKER_NAME##')
genericobj.data
genericobj.digit
genericobj.router
subobj=Sub.new
subobj.data

Here when I try to create a new subclass object I get the following error
"home/user/workspace/Parser/generic.rb:38:in `initialize': wrong number of arguments (0 for 1) (ArgumentError)
from /home/user/workspace/Parser/generic.rb:38:in `new'
from /home/user/workspace/Parser/generic.rb:38

Am not trying to use a constructor for the subclass but I still get this error. Please someone tell me where am going wrong

Thanks in Advance

Well, you define the class initializer ( def initialize(str) ) to take an argument in the base class. You do not change this behavior in the derived class. You can do one of the following to solve your problem:

class Sub < Generic
   def initialize
      @str = ""
   end
end

Which defined a new initializer method in the derived class.

class Generic
   def initialize(str="")
      @str=str
   end
   # ...

Which assigns a default value if no value is provided
Or

subobj=Sub.new ""

Provide an empty value for the object you are trying to create.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.