I
Imobach González Sosa
Hi all,
I've trying to find out how to check the class of a parameter. Right, I
talking about this:
class TestClass
# arg1 must be String instance
def myMethod(arg1, arg2)
# Code, code and more code.
end
end
I think that I could solve in this way:
class TestClass
# arg1 must be a String instance
def myMethod(arg1, arg2)
if not arg1.kind_of?(String)
# Error! Some code must be added!
end
end
end
Right, we are going to suppose now that I want to add an Integer as attribute
(myAttribute):
class TestClass
attr_writer :myAttribute
...
end
This attribute must be writable. But, there's a little trouble:
How could I assure that the parameter passed to myAttribute= method is
Integer? Must I implement the method by myself?
class TestClass
def myAttribute=(value)
if not myAttribute
end
end
Can it be automatized in some way?
Thank you all very much!
I've trying to find out how to check the class of a parameter. Right, I
talking about this:
class TestClass
# arg1 must be String instance
def myMethod(arg1, arg2)
# Code, code and more code.
end
end
I think that I could solve in this way:
class TestClass
# arg1 must be a String instance
def myMethod(arg1, arg2)
if not arg1.kind_of?(String)
# Error! Some code must be added!
end
end
end
Right, we are going to suppose now that I want to add an Integer as attribute
(myAttribute):
class TestClass
attr_writer :myAttribute
...
end
This attribute must be writable. But, there's a little trouble:
How could I assure that the parameter passed to myAttribute= method is
Integer? Must I implement the method by myself?
class TestClass
def myAttribute=(value)
if not myAttribute
end
end
Can it be automatized in some way?
Thank you all very much!