This is only an acceptable solution if the user has the source code and is capable of modifying it. For how I test things with IronRuby, this isn't always possible. Seems odd to me that one of the most flexible language I know of can't read/integrate with another language due to code not following a rigid structure. Doesn't IronPython allow for this? I was fairly sure I could import non-standard .Net convention based code into it. -Andrew On Fri, Nov 19, 2010 at 2:41 PM, Shay Friedman <shay.friedman@gmail.com >wrote: > Look here: > http://www.ironshay.com/post/Working-with-NET-Lowe... > < http://www.ironshay.com/post/Working-with-NET-Lowe... > > Shay. > Excellent solution. I mean, really, all the C# classes should start with an uppercase letter, thats basically a standard, therefore this should be the only solution and I don't see no need to actually hack this otherwise into IronRuby. -- If I had six hours to chop down a tree, Id spend the first four of them sharpening my axe. -Abraham Lincoln
on 2010-11-19 16:52
on 2010-11-19 17:36
On Fri, Nov 19, 2010 at 4:48 PM, andrew Wilson <a.wilson82@gmail.com> wrote: > This is only an acceptable solution if the user has the source code and is > capable of modifying it. For how I test things with Why? Just use 'LowerCase = get_const("lowerCase")'. Actually I don't understand why one would code C# using camelStyle. The standard is CamelStyle. > IronRuby, this isn't always possible. Seems odd to me that one of the most > flexible language I know of can't read/integrate with another language due > to code not following a rigid structure. The fact that it is dynamic does not implicate that IronRuby should be able to read all kind of crazy naming styles, it should implicate the you could modify it to your needs with minimum amount of coding, just add something like this before you use that library in ruby: modul.constants.each do |const| eval "#{const.uppercase} = modul.const_get(const)" end This is only semi-pseudocode, but you should get the idea. Doesn't IronPython allow for this? I was fairly sure I could import > non-standard .Net convention based code into it. > True or False.
on 2010-11-19 17:39
Andrew,
Not sure I follow. IronRuby does support this via DotNetClassName =
Object.const_get("lower_case_dotnet_class_name"), so you don't need to
change your code. This is an issue because of Ruby itself; classes are
required to be Ruby constants, which syntactically can only start with
an
upper-case letter. Since IronRuby is syntactically equivalent to Ruby,
we
will not remove this rule. Instead, we either suggest changing your C#
code,
or if you can't, use const_get. WRT your IronPython comment, it doesn't
have
this issue because the Python language doesn't enforce a naming scheme
on
type names.
~Jimmy
on 2010-11-19 18:50
I disagree. You don't need to be able to modify the .NET source code to
get
this to work. You can use Ruby to make Ruby happy. The reason for the
friction is because .NET != Ruby. When you create a class in Ruby, you
are
actually creating an object that inherits from Class, and then you are
creating a constant that points to that object. In Ruby all constants
start
with an upper case character. Ruby doesn't allow you to create a class
that
starts with a lower case letter.
> class foo; def to_s; puts 'wha?!'; end; end
SyntaxError: (irb):1: class/module name must be CONSTANT
class foo; def to_s; puts 'wha?!'; end; end
^
IronRuby does a lot of work to match Ruby's conventions of snake_case
methods, but it cannot resolve a lower case namespace or class from
.NET. I
think IronRuby is doing the right thing here. Its very simple to setup
your
Ruby constants that point to your .NET namespaces and classes using the
method shown in the URL provided.
Foo = Object.const_get("foo")
Foo::Bar = Foo.const_get("bar")
bar = Foo::Bar.new
Ruby is awesome but it is not infinitely flexible. You gotta jump to
Lisp
for that. :)
on 2010-11-19 19:07
For some reason Jimmy's reply didn't show up in my inbox until I sent my reply. Sorry for the duplicate explanation.
on 2010-11-19 19:44
Ruby can do crazy stuff but it doesn't support one thing that C# does - camelCase names for classes and modules (because they're eventually constants). It just can't be done. Taking this into consideration, what name would you expect a camelCased C# class name get in IronRuby? its PascalCased form? and what if there are two classes in the C# assembly, one named camelCase and the second CamelCase - totally legit in C#... what would you expect to happen then? It's a problematic situation and I think IronRuby goes with the right solution here. Shay. On Fri, Nov 19, 2010 at 6:05 PM, Andrius Bentkus
on 2010-11-20 23:40
Hey guys.. it's very nice that you all say the same thing, but it
doesn't work in IronRuby 1.1.1:
>>> Object.const_get "foo"
(ir):1:in `const_get': `foo' is not allowed as a constant name
(NameError)
from (ir):1
If this would've worked then I wouldn't have had to ask the question
in the first place :)
Kind regards,
Tinco Andringa
on 2010-11-21 00:06
Can you send a link to the assembly that defines the class you are trying to use? Tomas
on 2010-11-21 00:47
http://code.google.com/p/bwapi-mono-bridge/ here it is :) Thanks On Sat, Nov 20, 2010 at 11:53 PM, Tomas Matousek
on 2010-11-21 00:47
Okey, I just tried it myself on those assemblies, and now I find it
actually does work :D Sorry guys :) I was thrown off by the error that
is thrown when the constant with the lower case name doesn't exist. I
failed at first because I tried Object.const_get('bwapi') instead of
BWAPI.const_get('bwapi').
Thanks for the tips :)
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.