From: Steven Ketcham Date: 2003-06-01T02:00:29+09:00 Subject: newbie questions Moving from C++ Q1.) Is there an equivalent to enumerated types? Q2.) Is there an equivalent to the const declaration for function parameters? What prevents a function parameter from being accidently changed? Q3.) Is this the correct way to handle Hash containers and the objects they hold? Thanks! class TransCountHolder attr_accessor :siteKey, :siteName, :errors, :tranfersCounted, :baudAverage end class TransferSummary # const values - enumerated types???? enum {SiteList, TransferErrorCount, BaudRateAverage, TransferErrorCount} SiteList = 0 TransferErrorCount = 1 BaudRateAverage = 2 TransferCount = 3 def initialize(startDate, endDate, siteKey) ...snip... @countsContainer = Hash.new end def doSummary # site list doSql (getSiteListSQL(), SiteList) # transfer error count doSql (getTransferErrorCountSQL(), TransferErrorCount) # baud rate average doSql (getTransferBaudRateAverageSQL(), BaudRateAverage) # transfer count doSql (getTransferCountSQL(), TransferCount) end # what prevents whichFunction parameter from being changed???? # it would seem the case statement could be replaced by some other language feature???? def doSql(sqlStmt, whichFunction) database = DatabaseFunctions.new database.doSql( sqlStmt ) do |dataset| row.each_with_name do |siteKey, value| case whichFunction # SiteList when SiteList then transferSummaryCountHolder = TransCountHolder.new(siteKey, value) @countsContainer[SiteKey] = transferSummaryCountHolder # TransferErrorCount when TransferErrorCount then @countsContainer[siteKey].errors = value # BaudRateAverage when BaudRateAverage then @countsContainer[siteKey].baudAverage = value # TransferCount when TransferCount then @countsContainer[siteKey].tranfersCounted = value end end end database.finish end ...various functions snipped... end