Re: Lowercase classname

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 F. <[email protected]

wrote:
Look here:

http://www.ironshay.com/post/Working-with-NET-Lowercase-Namespaces-and-Classes-in-IronRuby.aspx

<
http://www.ironshay.com/post/Working-with-NET-Lowercase-Namespaces-and-Classes-in-IronRuby.aspx

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 Fri, Nov 19, 2010 at 4:48 PM, andrew Wilson [email protected]
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.

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

For some reason Jimmy’s reply didn’t show up in my inbox until I sent my
reply. Sorry for the duplicate explanation.

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

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. :slight_smile:

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 :slight_smile:

Kind regards,
Tinco Andringa

Can you send a link to the assembly that defines the class you are
trying to use?

Tomas

Google Code Archive - Long-term storage for Google Code Project Hosting. here it is :slight_smile:

Thanks

On Sat, Nov 20, 2010 at 11:53 PM, Tomas M.

Okey, I just tried it myself on those assemblies, and now I find it
actually does work :smiley: Sorry guys :slight_smile: 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 :slight_smile: