Is there a way to make a method that can both accept a parameter, but iscan also able to not be called with parameters thereby making the paramwithout one, in which case the method nil
example
declaration
def some_func(some_param)
usage of some_param || something else if params is nil
end
Callingparameter is regarded nil
like the method with and without paramsfollowing?
some_func(variable)
some_func
usage could be if params is loaded it can be passed. if not load it from database.
As far as i can tell you cant make to seperate method one with and one without params. Which would also be a bad solution i relation to maintainbability and duplicated code. This does NOT do the trick.
def determine_data_type(stats_category)
data_type = nil
case stats_category
when *integer_unit
data_type = DATATYPES::INTEGER
when *float_unit
data_type = DATATYPES::FLOAT
when *string_unit
data_type = DATATYPES::STRING
end
data_type
end
def determine_data_type
data_type = nil
case stats_category.unit #load from database
when *integer_unit
data_type = DATATYPES::INTEGER
when *float_unit
data_type = DATATYPES::FLOAT
when *string_unit
data_type = DATATYPES::STRING
end
data_type
end
What im aiming for is something like
def determine_data_type(stats_category)
data_type = nil
case stats_category || stats_category.unit #load from database
when *integer_unit
data_type = DATATYPES::INTEGER
when *float_unit
data_type = DATATYPES::FLOAT
when *string_unit
data_type = DATATYPES::STRING
end
data_type
end