I've got a class just like this:
class Equipment
attr_reader :text
attr_reader :name
attr_reader :array1
attr_reader :number
end
then, I want to make 2 constructors with 3 parameters each:
1º one -> (text,name,array1)
2º one -> (text, name,number)
The first one as an argument has an array and the other one has an integer (1,2...), so I need to define both constructors so when I create an object of this class it makes a difference between array or integer as the 3º argument.
Any ideas?
EDIT.: I thought this:
def initialize(text = "", name = "", array = array.new, number =0)
@text = text
@name = name
@array1 = array
@number = number
end
(initializing all of them) then:
def Equipment.newc_witharray(sometext, somename, somearray)
@text = sometext
@name = somename
@array1 = somearray
end
def Equipment.newc_withint(sometext, somename, somenumber)
@text = text
@name = name
@number = somenumber
end
and finally calling objects like this:
character1 = Equipment.newc_withint("Barbarian", "conan", 3)
shouldn't this work?