Hi Is there a way for me to call an overloaded constructor?? I want to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been searching quite a bit and haven''t seen anything so far. Thank you, Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091112/135374bf/attachment.html>
System::DateTime.method(:clr_new).overload(Fixnum, Fixnum, Fixnum).call 2009, 9, 28 --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Google Wave: portocarrero.ivan at googlewave.com Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown <patrickcbrown at gmail.com>wrote:> Hi > > Is there a way for me to call an overloaded constructor?? I want > to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been > searching quite a bit and haven''t seen anything so far. > > Thank you, > Patrick > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091113/18e521f4/attachment.html>
CLR DateTime type is currently mapped to Time Ruby class, so "new" uses only Ruby constructors to be compatible. However, you can use clr_new to call the CLR constructor for any CLR type with a public constructor: Time.clr_new(2009, 9, 28) You can also get the constructor method and call it like so: Time.clr_ctor.call(2009, 9, 28) This is useful when there are multiple overloads of the constructor among which we are not able to choose based upon the types of the actual arguments. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Patrick Brown Sent: Thursday, November 12, 2009 3:49 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] call an overloaded constructor?? Hi Is there a way for me to call an overloaded constructor?? I want to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been searching quite a bit and haven''t seen anything so far. Thank you, Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091113/54eacad9/attachment.html>
But you can just use the ruby way and that is a lot less noisy for a local time Time.local 2009, 9, 28 http://ruby-doc.org/core/classes/Time.html#M000254 for utc Time.utc 2009, 9, 29 http://ruby-doc.org/core/classes/Time.html#M000252 It still creates a System::DateTime underneath --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Google Wave: portocarrero.ivan at googlewave.com Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown <patrickcbrown at gmail.com>wrote:> Hi > > Is there a way for me to call an overloaded constructor?? I want > to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been > searching quite a bit and haven''t seen anything so far. > > Thank you, > Patrick > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091113/c9d67dea/attachment.html>
OOooooh that?s pretty?. J From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ivan Porto Carrero Sent: Thursday, November 12, 2009 4:07 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] call an overloaded constructor?? System::DateTime.method(:clr_new).overload(Fixnum, Fixnum, Fixnum).call 2009, 9, 28 --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Google Wave: portocarrero.ivan at googlewave.com Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown <patrickcbrown at gmail.com> wrote: Hi Is there a way for me to call an overloaded constructor?? I want to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been searching quite a bit and haven''t seen anything so far. Thank you, Patrick _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091112/4e153c5e/attachment-0001.html>
Hi That is fine in this case, can you tell me, in cases where I can''t fall back on a ruby class, is there a way to call an overloaded constructor? Your reply makes me worry a bit more. Thanks, Patrick On Thu, Nov 12, 2009 at 7:11 PM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:> But you can just use the ruby way and that is a lot less noisy > > for a local time > > Time.local 2009, 9, 28 > http://ruby-doc.org/core/classes/Time.html#M000254 > > for utc > Time.utc 2009, 9, 29 > http://ruby-doc.org/core/classes/Time.html#M000252 > > It still creates a System::DateTime underneath > > --- > Met vriendelijke groeten - Best regards - Salutations > Ivan Porto Carrero > Blog: http://flanders.co.nz > Google Wave: portocarrero.ivan at googlewave.com > Twitter: http://twitter.com/casualjim > Author of IronRuby in Action (http://manning.com/carrero) > > > > On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown <patrickcbrown at gmail.com>wrote: > >> Hi >> >> Is there a way for me to call an overloaded constructor?? I want >> to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been >> searching quite a bit and haven''t seen anything so far. >> >> Thank you, >> Patrick >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091112/0f106823/attachment.html>
Hi Patrick, Assuming you have the next C# class in C:\CustomAssembly.dll: namespace ClassLibrary2 { public class Class1 { public Class1(int a) { Console.WriteLine(a); } public Class1(int a, string s) { Console.WriteLine("{0} and {1}",a,s); } public Class1(bool b) { Console.WriteLine("b = {0}",b); } } } There are several constructors here. All you have to do to call a specific constructor via IronRuby, is to get the constructor method object (with clr_ctor like Tomas said), use the overload method to pick up the needed overload and call it. For example, the next IronRuby code executes all three constructors of the custom class above: require ''c:\CustomAssembly.dll'' include ClassLibrary2 # Call Class1(int a) constructor: Class1.clr_ctor.overload(System::Int32).call 1 # Prints "1" # Call Class1(int a, string s) constructor Class1.clr_ctor.overload(System::Int32, System::String).call 1, "yes" # Prints "1 and yes" # Call Class1(bool b) constructor: Class1.clr_ctor.overload(System::Boolean).call true # Prints "b = true" Hope it helps, Shay. -- -------------------------------------------------- Shay Friedman Author of IronRuby Unleashed http://www.IronShay.com Follow me: http://twitter.com/ironshay On Fri, Nov 13, 2009 at 4:18 AM, Patrick Brown <patrickcbrown at gmail.com>wrote:> Hi > > That is fine in this case, can you tell me, in cases where I can''t fall > back on a ruby class, is there a way to call an overloaded constructor? > Your reply makes me worry a bit more. > > Thanks, > Patrick > > > On Thu, Nov 12, 2009 at 7:11 PM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote: > >> But you can just use the ruby way and that is a lot less noisy >> >> for a local time >> >> Time.local 2009, 9, 28 >> http://ruby-doc.org/core/classes/Time.html#M000254 >> >> for utc >> Time.utc 2009, 9, 29 >> http://ruby-doc.org/core/classes/Time.html#M000252 >> >> It still creates a System::DateTime underneath >> >> --- >> Met vriendelijke groeten - Best regards - Salutations >> Ivan Porto Carrero >> Blog: http://flanders.co.nz >> Google Wave: portocarrero.ivan at googlewave.com >> Twitter: http://twitter.com/casualjim >> Author of IronRuby in Action (http://manning.com/carrero) >> >> >> >> On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown <patrickcbrown at gmail.com>wrote: >> >>> Hi >>> >>> Is there a way for me to call an overloaded constructor?? I want >>> to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been >>> searching quite a bit and haven''t seen anything so far. >>> >>> Thank you, >>> Patrick >>> >>> _______________________________________________ >>> Ironruby-core mailing list >>> Ironruby-core at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ironruby-core >>> >>> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091113/8bae0551/attachment.html>
Hello Thank you all for your help and I have to say that I am sorry also, I missed the other replies where you came right out and told me how to do it, for some reason I only saw the one that mapped the DateTime to the Time object, you all provided very good answers to my question and I really appreciate it. Patrick On Fri, Nov 13, 2009 at 1:15 AM, Shay Friedman <shay.friedman at gmail.com>wrote:> Hi Patrick, > > Assuming you have the next C# class in C:\CustomAssembly.dll: > namespace ClassLibrary2 > { > public class Class1 > { > public Class1(int a) > { > Console.WriteLine(a); > } > public Class1(int a, string s) > { > Console.WriteLine("{0} and {1}",a,s); > } > public Class1(bool b) > { > Console.WriteLine("b = {0}",b); > } > } > } > > There are several constructors here. All you have to do to call a specific > constructor via IronRuby, is to get the constructor method object (with > clr_ctor like Tomas said), use the overload method to pick up the needed > overload and call it. > For example, the next IronRuby code executes all three constructors of the > custom class above: > require ''c:\CustomAssembly.dll'' > > include ClassLibrary2 > > # Call Class1(int a) constructor: > Class1.clr_ctor.overload(System::Int32).call 1 > # Prints "1" > > # Call Class1(int a, string s) constructor > Class1.clr_ctor.overload(System::Int32, System::String).call 1, "yes" > # Prints "1 and yes" > > # Call Class1(bool b) constructor: > Class1.clr_ctor.overload(System::Boolean).call true > # Prints "b = true" > > Hope it helps, > Shay. > > -- > -------------------------------------------------- > Shay Friedman > Author of IronRuby Unleashed > http://www.IronShay.com <http://www.ironshay.com/> > Follow me: http://twitter.com/ironshay > > > On Fri, Nov 13, 2009 at 4:18 AM, Patrick Brown <patrickcbrown at gmail.com>wrote: > >> Hi >> >> That is fine in this case, can you tell me, in cases where I can''t fall >> back on a ruby class, is there a way to call an overloaded constructor? >> Your reply makes me worry a bit more. >> >> Thanks, >> Patrick >> >> >> On Thu, Nov 12, 2009 at 7:11 PM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote: >> >>> But you can just use the ruby way and that is a lot less noisy >>> >>> for a local time >>> >>> Time.local 2009, 9, 28 >>> http://ruby-doc.org/core/classes/Time.html#M000254 >>> >>> for utc >>> Time.utc 2009, 9, 29 >>> http://ruby-doc.org/core/classes/Time.html#M000252 >>> >>> It still creates a System::DateTime underneath >>> >>> --- >>> Met vriendelijke groeten - Best regards - Salutations >>> Ivan Porto Carrero >>> Blog: http://flanders.co.nz >>> Google Wave: portocarrero.ivan at googlewave.com >>> Twitter: http://twitter.com/casualjim >>> Author of IronRuby in Action (http://manning.com/carrero) >>> >>> >>> >>> On Fri, Nov 13, 2009 at 12:49 AM, Patrick Brown < >>> patrickcbrown at gmail.com> wrote: >>> >>>> Hi >>>> >>>> Is there a way for me to call an overloaded constructor?? I want >>>> to say date = new DateTime(2009,9,28) using IronRuby 0.9.2. I have been >>>> searching quite a bit and haven''t seen anything so far. >>>> >>>> Thank you, >>>> Patrick >>>> >>>> _______________________________________________ >>>> Ironruby-core mailing list >>>> Ironruby-core at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/ironruby-core >>>> >>>> >>> >>> _______________________________________________ >>> Ironruby-core mailing list >>> Ironruby-core at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ironruby-core >>> >>> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091113/7dc52c0f/attachment-0001.html>