On 11/18/06, Li Chen <chen_li3 / yahoo.com> wrote: > Hi all, > > I recently play with win32ole library. In order to use it I put a line > at the top of the script > > require 'win32ole' > > so that Ruby knows where to find the library. It is my understanding I > should be able to access all the classes/modules within the file. But > this is not the case. In order to get access to ExcelConst I need to add > two more lines > > module ExcelConst > end > > near the top of the script. > > I am a little bit confused. Why is that? Is this only special to > win32ole library or common to many Ruby libraries? > > Any comments will be appriciated. > > Li > > > And the follows are the fragment of the script: > ### > require 'win32ole' > > module ExcelConst > end > > excel = WIN32OLE.new("Excel.Application") > workbook = excel.Workbooks.Add > excelchart = workbook.Charts.Add > .... > WIN32OLE.const_load(excel, ExcelConst) > excelchart.ChartType = ExcelConst::XlConeCol You have to define the moduke ExcelConst, because it is not a part of the library, it is *your* module that the library will fill with constants (see the line with WIN32OLE.const_load). You can use any name for it (i.e. MySuperExcelModuleForConstants). You can even reuse any existing module for that (including any class). If you read the documentation you can omit the module name (the second parameter to WIN32OLE) and the constants will be added to WIN32OLE itself. You can add the constants to Kernel module, or Object class so that you can use them without prefix (and thus polluting the global namespace, although sometimes it might be handy).