July 2011
Intermediate to advanced
400 pages
8h 46m
English
For a simple (but, in real-world programming, potentially serious) example of how relying on the modified values of arguments rather than on explicit return values can introduce undesirable dependencies on implementation details, see side_effects.rb. Here is a method called stringProcess that takes two string arguments, messes about with them, and returns the results:
side_effects.rb
def stringProcess( aStr, anotherStr )
aStr.capitalize!
anotherStr.reverse!.capitalize!
aStr = aStr + " " + anotherStr.reverse!
return aStr
endLet’s assume the object of the exercise is to take two lowercase strings and return a single string that combines these two strings, separated by a space and with the first ...
Read now
Unlock full access