I wonder if it should be checked that the arguments passed to the method belong to a particular class.
eg.
def type(hash = {}, array = []) # validate before raise "first argument needs to be a hash" unless hash.class == Hash raise "second argument needs to be an array" unless array.class == Array # actual code end
Is it possible to do this, or is it just cumbersome and wasting time checking all the arguments passed?
Are there circumstances where you would like to have this extra security and circumstances where you will not be worried?
Share your impressions!
, , , . , respond_to? . : [], .
respond_to?
OpenStruct - -, true hash.class==Hash. .
hash.class==Hash
, , ; , IDictionary<T>. Ruby , , , , , , , , . , .
IDictionary<T>
, . Ruby Duck Typing.
, . - " , ".
/ , Ruby . , Ruby.
, , , . , , - . Ruby, . , , , , . , , .