# Re: Lowercase classname

**URL:** <https://www.ruby-forum.com/t/re-lowercase-classname/199370>\
**Category:** IronRuby\
**Created:** [November 19, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370 "2010-11-19T16:52:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 19, 2010, 4:52pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/1 "2010-11-19T16:52:07Z")

</div>

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. \<removed\_email\_address@domain.invalid

> 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)

> \<  
> [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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 19, 2010, 5:36pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/2 "2010-11-19T17:36:05Z")

</div>

On Fri, Nov 19, 2010 at 4:48 PM, andrew Wilson [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 19, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/3 "2010-11-19T17:39:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 19, 2010, 7:07pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/4 "2010-11-19T19:07:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 19, 2010, 7:44pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/5 "2010-11-19T19:44:16Z")

</div>

## 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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 19, 2010, 6:50pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/6 "2010-11-19T18:50:53Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 20, 2010, 11:40pm UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/7 "2010-11-20T23:40:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 21, 2010, 12:06am UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/8 "2010-11-21T00:06:17Z")

</div>

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

Tomas

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 21, 2010, 12:47am UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/9 "2010-11-21T00:47:36Z")

</div>

[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/bwapi-mono-bridge/) here it is 🙂

Thanks

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

---

<div class="post-metadata">

**Author:** ![andrew\_Wilson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@andrew\_Wilson](https://www.ruby-forum.com/u/andrew_Wilson)\
**Post date:** [November 21, 2010, 12:47am UTC](https://www.ruby-forum.com/t/re-lowercase-classname/199370/10 "2010-11-21T00:47:37Z")

</div>

Okey, I just tried it myself on those assemblies, and now I find it  
actually does work 😃 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 🙂
