ruby - Data Types compare and return result -


based on argument supplied function. follow through test produce perfect function accounts expectations.

for strings, return length. nil return string 'no value' booleans return boolean numbers return string showing how compares hundred e.g. 67 return 'less 100' 4034 return 'more 100' arrays return 3rd index, or nil if doesn't exist

this same @t.aoukar, less verbose.

def perfect(a)   case     when string       a.size     when array       a[2]     when trueclass, falseclass           when nilclass       "no value"     when numeric       #insert code   end end 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -