Ruby is one of my favorite languages right now, but handles return values for methods very differently than languages like Java. Ruby does not require an explicit 'return' statement, but can return the last executed statement results by default. This can be confusing.
Discovering what this return value might be can be more time consuming that is necessary and is immediately taken care of by simply supplying a 'return' statement. Cost is nothing, results are clarity. I provide an example from this project:
##
# Cleans up this packages source build directory.
#
# RETURNS: boolean - True if the completes successfully,
# otherwise false.
##
def remove_build
puts "Removings build..."
if ($REMOVE_BUILD_SOURCES)
buildSourcesLocation = "#{$BUILD_LOCATION}/#{srcDir}"
if (!File.directory?(buildSourcesLocation))
return true
end
if (!FileUtils.rm_rf buildSourcesLocation, :verbose => true )
return false
end
end
return true
end
* This is a cross post.
0 comments:
Post a Comment