FYI I added this to the namespaces .NET doc page: http://ironruby.net/Documentation/.NET/Namespaces
From: ironruby-core-boun...@rubyforge.org [mailto:ironruby-core-boun...@rubyforge.org] On Behalf Of Tomas Matousek Sent: Thursday, June 11, 2009 3:27 PM To: Shri Borde; ironruby-core@rubyforge.org Subject: Re: [Ironruby-core] Math module after "include System" This is a consequence of how constant resolution works in Ruby. We don't do anything special for namespaces. No constants are copied on module inclusion - only ancestor lists are updated. The unqualified constant resolution searches lexical scopes first (from the inner-most to the outer-most). If the scope is a module scope then it looks into that module (but not its ancestors). If it is a top-level scope then it looks into its associated module, which is Object for normal top-level scope or the wrapping module for wrapped top-level scope (Kernel#load(wrapped = true)). If the constant is not found the inner-most module scope (or top-level scope) is checked again, now including its ancestors. If the constant is still not resolved Object and its ancestors are inspected. So in your case, the first module to look to is Object - the inner-most scope associated with a module is the top-level scope associated with Object. So, Object::Math, i.e. the built-in Math module, is found first. The included module System is a mix-in on Object (top-level call to "include" includes the mixin into the nominal class of the current self, which is Object). Tomas From: Shri Borde Sent: Thursday, June 11, 2009 3:00 PM To: ironruby-core@rubyforge.org; Tomas Matousek Subject: RE: Math module after "include System" "include System" is useful for interactive session to bring the whole namespace into scope in bulk, and Ruby programmers used to doing "include ModuleName" will probably end up doing "include ClrNamespace". Both forms have their uses. From: ironruby-core-boun...@rubyforge.org [mailto:ironruby-core-boun...@rubyforge.org] On Behalf Of Jim Deville Sent: Thursday, June 11, 2009 2:35 PM To: ironruby-core@rubyforge.org; Tomas Matousek Subject: Re: [Ironruby-core] Math module after "include System" My solution, when I am going to be using the class name a lot, is to put an alias at the top of the file, for example, SArray = System::Array. That allows me to save some characters, and come close to what include System would have done. JD ...there is no try From: ironruby-core-boun...@rubyforge.org [mailto:ironruby-core-boun...@rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, June 11, 2009 2:32 PM To: Tomas Matousek Cc: ironruby-core@rubyforge.org Subject: Re: [Ironruby-core] Math module after "include System" So only constants and classes that did not already exist are copied? The docs don't mention this. Oh well. Something for folks to be aware of if they do "include System". Names like Math, Thread, etc which clash between Ruby and the System namespace will not be copied... From: Tomas Matousek Sent: Thursday, June 11, 2009 2:06 PM To: Shri Borde Subject: RE: Math module after "include System" Yes, that is expected. The Ruby equivalent would be: module S class Math end end include S p Math.singleton_methods ["atan", "frexp", "sin", "exp", "tanh", "erf", "asin", "sqrt", "cos", "atanh", "sinh", "hypot", "acos", "log10", "atan2" , "asinh", "cosh", "ldexp", "tan", "log", "acosh", "erfc"] Tomas From: Shri Borde Sent: Thursday, June 11, 2009 1:31 PM To: Tomas Matousek Subject: Math module after "include System" After doing "include System", I was expecting System.Math to be directly accessible. However "Math" still refers to the Ruby builtin module. Is this expected? c:\vsl\Merlin\Main\Languages\Ruby\Samples\Tutorial>rbx IronRuby 0.5.0.0 on .NET 2.0.50727.3053 Copyright (c) Microsoft Corporation. All rights reserved. >>> Math.methods(false).sort => ["acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "cos", "cosh", "erf", "erfc", "exp", "frexp", "hypot", " ldexp", "log", "log10", "sin", "sinh", "sqrt", "tan", "tanh"] >>> include System => Object >>> AppDomain => System::AppDomain >>> Math => Math >>> Thanks, Shri
_______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core