# Default values for arguments

**URL:** <https://www.ruby-forum.com/t/default-values-for-arguments/68334>\
**Category:** Ruby\
**Created:** [September 11, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/default-values-for-arguments/68334 "2006-09-11T21:31:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [September 11, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/default-values-for-arguments/68334/1 "2006-09-11T21:31:48Z")

</div>

For some odd reason, the default values for some of the optional  
arguments are not getting assigned, namely the \_dateTime argument. As a  
result, I have to add the “if blahblah.nil?” hacks below. Anyone know  
what’s going on here?

def saveResults(\_scriptPoint,   
\_scriptName,   
\_testResult=self.RESULTVALUE\_SUCCESS,   
\_seqNo=nil,   
\_dateTime=Time.now(),   
\_comments=nil,   
\_imagePath=nil,   
\_imageBinary=nil)

```
#-- open connection with SQL Server database
@sqlConnection = SqlClient::SqlConnection.new(@dataSource, 

```

@initialCatalog)

```
#-- determine next sequence number for the current logID if seqNo 

```

parameter not passed  
\_seqNo = self.getMaxSeqNo() + 1 if \_seqNo.nil?

```
#-- !!hacking starts here!!
_dateTime = Time.now() if _dateTime.nil?
_comments = "".to_s() if _comments.nil?
_testResult = SqlErrorLogger::RESULTVALUE_INFO if _testResult.nil?

sqlInsert = \
  "INSERT INTO " \
    "qa_loggerresults " \
  "(" \
    "logid, " \
    "seqno, " \
    "logdate, " \
    "scriptpoint, " \
    "scriptname, " \
    "comments, " \
    "testresult"

#-- append the additional column names if their values were passed
sqlInsert.concat(", screenimagepath") unless _imagePath.nil?
sqlInsert.concat(", screenimage") unless _imageBinary.nil?

#-- append a closing parenthesis
sqlInsert.concat(") ")

sqlInsert.concat( \
  "VALUES " \
  "(" \
    "#{self.newLogID}, " \
    "#{_seqNo}, " \
    "'#{self.formatDateTime(_dateTime)}', " \
    "'#{_scriptPoint}', " \
    "'#{_scriptName}', " \
    "'#{_comments}', " \
    "#{_testResult}")

#-- append the additional column values if they're not nil
sqlInsert.concat(", '#{_imagePath}'") unless _imagePath.nil?
sqlInsert.concat(", #{_imageBinary}") unless _imageBinary.nil?

#-- append a closing parenthesis
sqlInsert.concat(")")

puts(sqlInsert)

@sqlConnection.execute(sqlInsert)

```

end #-- SqlErrorLogger.saveResults()
