# Agdlr test w/ ruby string

**URL:** <https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447>\
**Category:** IronRuby\
**Created:** [April 1, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447 "2009-04-01T15:16:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jb\_Evain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/67e7ee/32.png) [@Jb\_Evain](https://www.ruby-forum.com/u/Jb_Evain)\
**Post date:** [April 1, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447/1 "2009-04-01T15:16:06Z")

</div>

Hey,

Moonlight currently fails the following agldr test:

it ‘verifies SetProperty works’ do  
new\_ctl = HtmlPage.Document.CreateElement(‘div’)  
new\_value = “This is added by Merlin SL Test!”  
new\_ctl.SetProperty(“innerHTML”, new\_value)  
new\_ctl.GetProperty(“innerHTML”).should.equal new\_value.to\_clr\_string  
end

it passes if I change the SetProperty line to:

new\_ctl.SetProperty(“innerHTML”, new\_value.to\_clr\_string)

SetProperty’s signature is `void SetProperty(string name, object value)`, so I’d except it to convert the name “innerHTML” to a  
clr\_string, but not the value argument.

Is IronRuby doing some conversion here, or is it Silverlight doing  
interesting things when marshalling the value?

---

<div class="post-metadata">

**Author:** ![Jb\_Evain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/67e7ee/32.png) [@Jb\_Evain](https://www.ruby-forum.com/u/Jb_Evain)\
**Post date:** [April 1, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447/2 "2009-04-01T18:28:15Z")

</div>

SetProperty converts Ruby string “innerHTML” to CLR string because its  
first parameter is strongly typed to CLR string. The second parameter is  
not and hence no conversion occurs.

This should work:

new\_ctl.SetProperty(“innerHTML”, new\_value)  
new\_ctl.GetProperty(“innerHTML”).should.equal new\_value

The current implementation “==” compares Ruby strings and CLR strings by  
value.  
The implementation of “eql?” doesn’t:

> > > x = ‘str’  
> > > =\> “str”
> 
> > > y = x.to\_clr\_string  
> > > =\> ‘str’
> 
> > > x == y  
> > > =\> true
> 
> > > x.eql? y  
> > > =\> false

Which is similar to numerics in MRI:

irb(main):001:0\> 1 == 1.0  
=\> true  
irb(main):002:0\> 1.eql? 1.0  
=\> false  
irb(main):003:0\> exit

Would it be better to override “eql?” on string to compare Ruby string  
and CRL string equal if they have the same value?

Tomas

---

<div class="post-metadata">

**Author:** ![Jb\_Evain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/67e7ee/32.png) [@Jb\_Evain](https://www.ruby-forum.com/u/Jb_Evain)\
**Post date:** [April 1, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447/3 "2009-04-01T19:21:07Z")

</div>

Hey Tomas,

On 4/1/09, Tomas M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> SetProperty converts Ruby string “innerHTML” to CLR string because its first parameter is strongly typed to CLR string. The second parameter is not and hence no conversion occurs.

Alright that’s what I expected.

> The current implementation “==” compares Ruby strings and CLR strings by value.

> > > “” == “”.to\_clr\_string  
> > > =\> false

I see 🙂 Now to fix it in Mono.

Thanks,

---

<div class="post-metadata">

**Author:** ![Jb\_Evain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/67e7ee/32.png) [@Jb\_Evain](https://www.ruby-forum.com/u/Jb_Evain)\
**Post date:** [April 2, 2009, 10:24am UTC](https://www.ruby-forum.com/t/agdlr-test-w-ruby-string/164447/4 "2009-04-02T10:24:29Z")

</div>

On 4/1/09, Jb Evain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is IronRuby doing some conversion here, or is it Silverlight doing  
> interesting things when marshalling the value?

Alright, so for the curious, after an update, the string comparison  
works ok on Moonlight.

The issue is indeed marshaling in Silverlight, which decides that  
innerHTML is a string property, so it stringifies whatever you give it  
to. Not obvious 🙂
